我想通过编辑更改我的应用程序中的所有 toasts themes.xml
。
我<item name="buttonStyle">@style/MyButton</item>
用来更改我的按钮,是否有与 Toast 类似的东西,或者我是否必须创建和使用MyToast
扩展内置 Toast 的类?
我想通过编辑更改我的应用程序中的所有 toasts themes.xml
。
我<item name="buttonStyle">@style/MyButton</item>
用来更改我的按钮,是否有与 Toast 类似的东西,或者我是否必须创建和使用MyToast
扩展内置 Toast 的类?
您可以使用以下方法更改 Toast 的背景:
<style name="myTheme" parent="@android:styles/Theme.Holo">
<item name="android:toastFrameBackground">@android:drawable/my_toast</item>
</style>
试试这个:
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();