2016-05-21 56 views
0

我想確保涵蓋所有版​​本與這個問題有關,但我想更改我的工具欄的文本顏色。目前它是黑色的,我希望將它改爲白色。我知道有不同的治療API < 21和API 23無法更改工具欄文本顏色

這裏是我的主題:

<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light"> 
    <item name="android:radioButtonStyle">@style/Theme.AppCompat.DayNight</item> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
    <item name="android:textColor">@color/black</item> 
    <item name="android:textColorPrimary">@color/black</item> 
    <item name="android:textColorSecondary">@color/white</item> 

    <item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item> 
    <item name="colorControlActivated">@android:color/holo_red_light</item> 
    <item name="colorControlNormal">@android:color/black</item> 
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item> 

</style> 


<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle"> 
    <item name="color">@android:color/white</item> 
</style> 

<style name="MyTheme.ActionBarStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"> 
    <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item> 
</style> 

<style name="MyTheme.ActionBar.TitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"> 
    <item name="colorAccent">@color/white</item> 
    <item name="android:textColorPrimary">@color/white</item> 
</style> 

這裏是我的工具欄的xml:

<android.support.v7.widget.Toolbar 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/toolbar_test" 
android:layout_height="wrap_content" 
android:layout_width="match_parent" 
android:fitsSystemWindows="true" 
android:minHeight="?attr/actionBarSize" 
android:theme="@style/MyTheme" 
android:background="@color/actionRed"> 

活動XML :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <include 
     android:id="@+id/tool_bar" 
     layout="@layout/toolbar_one" /> 

     <android.support.v4.view.ViewPager 
      android:id="@+id/home_polls_viewpager_fragment_container" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1"> 

     </android.support.v4.view.ViewPager> 

</LinearLayout> 

回答

1
For changing toolbar text color, you can use this theme 

<style name="HomeTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <item name="colorPrimary">@color/black</item> 
    <item name="colorPrimaryDark">@color/black</item> 
    <item name="android:windowBackground">@color/bg</item> 
    <item name="android:textColorSecondary">@color/white</item> 
    <item name="android:textColorPrimary">@color/white</item> 
    <item name="colorAccent">@color/white</item> 
    <item name="android:activatedBackgroundIndicator">@drawable/drawer_list_selector</item> 
</style> 

    and for toolbar, you can use 
    <android.support.v7.widget.Toolbar 
     android:id="@+id/main_toolbar" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:minHeight="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     android:titleTextColor="@color/white" 
     app:popupTheme="@style/AppTheme.PopupOverlay" > 

    If still it not work, you can change toolbar color at programing time by 
     toolbar.setTitleColor(getResources.getColor(R.color.white) 

    Even still it not work, you can customize toolbar as 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/main_toolbar" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:minHeight="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay" > 


     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/accept_order" 
      android:layout_gravity="center" 
      android:textSize="@dimen/twenty" 
      android:textColor="@color/white" 
      android:id="@+id/toolbar_title" /> 
     </android.support.v7.widget.Toolbar>