簡體   English   中英

更改工具欄的背景顏色和標題

[英]Change Toolbar Background Color and Title

我正在嘗試更改設置為actionbartoolbar widgetbackgroundtitle

final Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);

它希望它像Google Play商店應用一樣。
應用->灰色(背景)和“應用”(標題)
我的應用程序->綠色(背景)和“我的應用程序”(標題)
所以我已經嘗試用

Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.my_awesome_toolbar);
toolbar.setTitle("Jiji");

toolbar toolbar = (Toolbar) rootView.findViewById(R.id.my_awesome_toolbar);
toolbar.setTitle("Jiji");
getActivity().setActionBar(toolbar); // error: incompatible types: android.support.v7.widget.Toolbar cannot be converted to android.widget.Toolbar

getActivity.setTitle("ododo") //works for a short moment

對於背景,只有一個名為setBackgroundDrawable的方法標記為“已棄用”,但該方法對我不起作用:-(可能已發布https://code.google.com/p/android/issues/detail?id= 78471&colspec = ID%20Type%20Status%20Owner%20Summary%20Stars

任何想法都歡迎:-)

我自己找到了解決方案
首先將Activity更改為ActionBarActivity然后可以使用getSupportActionBar()來處理工具欄背景,例如:

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#f44336")));

對於狀態欄,您可以使用setStatusBarColor,例如:

if (android.os.Build.VERSION.SDK_INT >= 21) {
    getWindow().setStatusBarColor(Color.parseColor("#e53935"));
}

歡呼ternes3

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM