2015-10-04 32 views
9

Mã của tôi là:Thay đổi thanh công cụ đề tài lập trình

<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"/> 

Tôi muốn thay đổi ứng dụng: chủ đề trong mã java. Tôi có thể tìm thấy bất kỳ phương pháp nào là toolbar.setTheme được sử dụng để thay đổi kiểu thanh công cụ không?

+2

Bạn chỉ có thể thay đổi màu nền và mã màu tiêu đề sử dụng: toolbar.setBackgroundColor (newColor); toolbar.setTitleTextColor (titleColor); – Lazai

+0

@Lazai cảm ơn bạn –

+0

Hãy thử cách này: https://stackoverflow.com/questions/31225189/how-to-change-appcompat-v21-toolbar-theme-programmatically –

Trả lời

0

Bạn có thể thay đổi nó theo chương trình như thế này:

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

toolbar.getContext().setTheme(R.style.ThemeOverlay_AppCompat_Dark_ActionBar); 
Các vấn đề liên quan