2013-04-05 30 views
6

我想通過編輯themes.xml來更改我應用程序中的所有敬酒。如何將烤麪包風格設置爲主題?

我正在使用<item name="buttonStyle">@style/MyButton</item>來改變我的按鈕,有沒有類似的東西,或者我必須創建並使用MyToast類,它擴展了內置的Toast?

回答

5

你可以改變你的麪包的背景是:

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

謝謝艾哈邁德,有沒有其他的定製而不是背景?其次是有所有項目名稱的表,如'android:toastFrameBackground' – guness 2013-04-07 10:07:40

+0

@bluebrain你不能用樣式設置重力等(如我所知道的那樣),你必須以編程的方式來完成。 Android是開源的,所以你可以在這裏找到一切:https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/themes.xml – Ahmad 2013-04-07 16:09:23

+2

你可以改變背景嗎?另一個SO帖子指出,toastFrameBackgound不公開。在API 18上,我收到一條錯誤消息,說沒有找到與該名稱匹配的資源。 http://stackoverflow.com/questions/19215326/styles-toast-background-no-resource-found-that-matches-the-given-name – spaaarky21 2014-03-03 22:48:15

-3

試試這個:

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(); 
+7

我沒有看到相關的「主題」(什麼這是關係到全局的,不單敬酒)在這裏,請你詳細說明答案? – guness 2013-04-05 12:47:25

相關問題