FYI: Причина вставки подчеркивания, вероятно, связана с тем, что вы используете ImprovedNamingStrategy . Он настроен на ваш объект Configuration . См. здесь для примера ...
Если вы не хотите подчеркивания, вы можете просто не устанавливать стратегию именования или устанавливать его в ранее найденную ранее DefaultNamingStrategy.
Изменение цветов тоста без каких-либо дополнительных макетов, 2018
Это очень простой способ изменения цвета фона фактического изображения тоста, а также цвет текста, он не требует каких-либо дополнительных макетов или каких-либо изменений XML:
Toast toast = Toast.makeText(context, message, duration);
View view = toast.getView();
//Gets the actual oval background of the Toast then sets the colour filter
view.getBackground().setColorFilter(YOUR_BACKGROUND_COLOUR, PorterDuff.Mode.SRC_IN);
//Gets the TextView from the Toast so it can be editted
TextView text = view.findViewById(android.R.id.message);
text.setTextColor(YOUR_TEXT_COLOUR);
toast.show();
Вы можете настроить собственный Android-тост, используя следующий код
/**
* ShowToast
*/
public class ShowToast {
public ShowToast(Context context, String info) {
Toast toast = Toast.makeText(context, Html.fromHtml("<font color='#e3f2fd' ><b>" + info + "</b></font>"), Toast.LENGTH_LONG);
toast.setGravity(Gravity.TOP, 0, 0);
toast.show();
}
}
Если вы хотите изменить фон, вы должны использовать пользовательский макет в тосте
Toast toast= Toast.makeText(YOUR ACTIVITY NAME ,Toast.LENGTH_SHORT);
View view =toast.getView();
view.setBackgroundColor(Color.GREEN); //any color your want
toast.show();
Добавляя к ответу @ AndroidKiller, вы также можете установить gravity
и пользовательский TextView
среди прочего, например так:
Toast toast = Toast.makeText(context, context.getResources().getString(resID), Toast.LENGTH_LONG);
LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE );
View toastView = li.inflate(R.layout.toast_hint_layout, null);
TextView text = (TextView) toastView.findViewById(R.id.hint_text_tv);
text.setText(resID);
toast.setView(toastView);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toastView.setBackgroundResource(R.drawable.toast_9_patch);
toast.show();
Обратите внимание, ваш фон для рисования должен быть девять -patch PNG
Вы можете даже добавить ImageView
и несколько TextView
с помощью XML следующим образом:
<LinearLayout android:id="@+id/layout_root"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="32dp"
android:layout_height="43dp"
android:src="@drawable/lightbulb"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:orientation="vertical"
>
<TextView
android:id="@+id/hint_text_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ccc"
android:textSize="14dp"
/>
<TextView
android:id="@+id/hint_text_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="(disable hints in preferences)"
android:textColor="#555"
android:textSize="11dp"
/>
</LinearLayout>
</LinearLayout>
Значение по умолчанию изменения жарит цвет сообщения и цвет фона в JAVA. Можно изменить цвет сообщения тоста и цвет фона этот путь..
Toast toast=Toast.makeText(MainActivity.this,"Signin button is clicked.",Toast.LENGTH_SHORT);
View view =toast.getView();
view.setBackgroundColor(Color.GREEN);
TextView toastMessage = (TextView) toast.getView().findViewById(android.R.id.message);
toastMessage.setTextColor(Color.RED);
toast.show();
Просто цвет текста тоста изменения этот путь..
Toast toast = Toast.makeText(getApplicationContext(), "Signup button is clicked.",Toast.LENGTH_SHORT);
TextView toastMessage=(TextView) toast.getView().findViewById(android.R.id.message);
toastMessage.setTextColor(Color.BLUE);
toast.show();