-1

此处操作栏中文本的默认颜色为黑色。我需要文本颜色为白色。如何在 actionbar 中将我的标题的颜色更改为默认颜色黑色到白色。

<!--
    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>

4

1 回答 1

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>

在每个Activity中,您可以在 onCreate 中调用此方法将 actionBar 设置为您的自定义 ActionBar:

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);
    }

并在 res--> values --> 样式下更改为:

    <resources>

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

</resources>

我希望这个能帮上忙

于 2015-07-06T09:26:41.280 回答