2015-10-04 65 views
9

我的代碼是:更改工具欄主題編程

<android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     android:minHeight="?attr/actionBarSize" 
     app:theme="@style/Toolbar_Theme"/> 

我想改變應用程序:主題java代碼。 我可以找到任何方法作爲toolbar.setTheme用於改變工具欄的風格?

+2

你只能改變背景顏色和標題使用顏色代碼: toolbar.setBackgroundColor(newColor); toolbar.setTitleTextColor(titleColor); – Lazai

+0

@Lazai謝謝 –

+0

試試這個:https://stackoverflow.com/questions/31225189/how-to-change-appcompat-v21-toolbar-theme-programmatically –

回答

0

您可以通過編程改變這樣的:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 

toolbar.getContext().setTheme(R.style.ThemeOverlay_AppCompat_Dark_ActionBar);