@style...">

How to set toast style as theme?

I want to change all the toasts in my application by editing themes.xml .

I use <item name="buttonStyle">@style/MyButton</item> to change my buttons, is there something similar with Toasts, or do I need to create and use the MyToast class that extends the built-in Toast?

+6
source share
3 answers

You can change the background of your toast as follows:

 <style name="myTheme" parent="@android:styles/Theme.Holo"> <item name="android:toastFrameBackground">@android:drawable/my_toast</item> </style> 
+5
source

I do not answer the original question, I just answer the question asked in one of the comments: "Is there a table for all element names, such as android: toastFrameBackground", because it can be useful, and I can not comment, because due to the lack of a "reputation number". So do not go down. Yes, there are two files that can provide you with all the attributes used by the Android operating system.

 Android Styles (styles.xml) - 

https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/values/styles.xml

 Android Themes (themes.xml) - 

https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/values/themes.xml

0
source

Try the following:

  Toast toast=new Toast(this); LayoutInflater inflater=this.getLayoutInflater(); View toastView=inflater.inflate(R.layout.toast_layout, (ViewGroup)findViewById(R.id.toastView)); TextView txtDate=(TextView)toastView.findViewById(R.id.txtDate); txtDate.setText("toast appeared at "+Calendar.getInstance().getTime().toLocaleString()); toast.setGravity(Gravity.CENTER, 0, 0); toast.setView(toastView); toast.show(); 
-3
source

All Articles