-1

此處操作欄中文本的默認顏色爲黑色。我需要文字顏色爲白色。如何在actiobar中將顏色更改爲默認顏色黑色到白色的標題。如何更改操作欄中文本的顏色,默認是黑色?

<!-- 
    Base application theme, dependent on API level. This theme is replaced 
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices. 



--> 
<style name="AppBaseTheme" parent="android:Theme.Light"> 
    <!-- 
     Theme customizations available in newer API levels can go in 
     res/values-vXX/styles.xml, while customizations related to 
     backward-compatibility can go here. 



    --> 
</style> 

<!-- Application theme. --> 
<style name="AppTheme" parent="AppBaseTheme"> 
    <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
</style> 

<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"> 
    <item name="android:background">@color/MyColor</item> 
    <item name="background">@color/MyColor</item> 
</style> 

<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light"> 
    <item name="android:actionBarStyle">@style/MyActionBar</item> 
    <item name="actionBarStyle">@style/MyActionBar</item> 
</style> 

+0

發佈style.xml是你創建的嗎? –

+0

@ρяσѕρєяK yes。 –

回答

0

您可以設置這樣一個自定義動作條:

custom_action_bar.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:background="#526e83" 
    android:descendantFocusability="blocksDescendants"> 

    <ImageView 
     android:id="@+id/ContactImageId" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/logo" 
     android:paddingLeft="100dp" 
     /> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:paddingTop="10dp"> 

     <TextView 
      android:id="@+id/CTS" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="15dp" 
      android:textColor="#ffffff" 
      android:text="CTS" 
      android:textStyle="bold"/> 

     <TextView 
      android:id="@+id/UserName" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="10dp" 
      android:textColor="#ffffff" 
      android:text="Welcome: HKH"/> 
    </LinearLayout> 
</LinearLayout> 

,並在每個活動可以CA LL這種方法的onCreate的動作條設置爲自定義動作條:

public void addTextToActionBar() { 

     android.support.v7.app.ActionBar actionBar = getSupportActionBar(); 
     actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME); 
     actionBar.setIcon(android.R.color.transparent); 
     actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#526e83"))); 
     View cView = getLayoutInflater().inflate(R.layout.custom_action_bar, null); 
     actionBar.setCustomView(cView); 
    } 

下水庫 - >數值 - >樣式改成這樣:

<resources> 

    <!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
    </style> 

</resources> 

我希望這將有助於

+0

<! - ActionBar style for Text Style,Background - >

+0

它沒」像我寫的@PritiRathod一樣工作? –