簡體   English   中英

如何自定義Android操作欄?

[英]How to Customize the Android Action Bar?

我的Android應用程序的操作欄不顯示'AndroidManifest.xml'標記中定義的圖標,我也無法更改操作欄的顏色或操作欄上的標題文本的顏色。

我目前使用的是最低API 16(Android Jellybean 4.1),而目標SDK是最新的(在撰寫本文時)為22。

我的styles.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/ActionBar</item>
    </style>

    <style name="ActionBar" parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
        <item name="android:background">#006699</item>
    </style>
</resources>

我的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="PACKAGE_NAME" >

<application
    android:allowBackup="true"
    android:icon="@drawable/logo_custom"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:logo="@drawable/logo_custom"
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

每當我在手機上運行該應用程序(運行4.4.4 KitKat API 19)時,我都會得到默認的黑色操作欄,其中沒有應用程序圖標。

有誰知道為什么它不會自定義?

感謝所有的幫助,在此先感謝。

注意:我是Android開發的新手。

在Styles.xml中嘗試一下。

    <style name="AppBaseTheme" parent="Theme.AppCompat.Light"></style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <item name="actionBarStyle">@style/MyActionBar</item>
    </style>

    <style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
        <!-- Support library compatibility -->
        <item name="colorControlNormal">@color/light_gray</item>
        <item name="background">@color/white</item>
        <item name="android:textColor">@color/white</item>
    </style>

編輯:

您可以通過編程方式更改操作欄的背景。

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.actionbar_background_color)));

您必須像這樣在color.xml中定義顏色代碼。

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="actionbar_background_color">#f4f2f2</color>
</resources>

我建議使用工具欄,因為它提供了幾乎所有您想要使用操作欄進行的自定義,您將在此處找到一個有效的示例

<style name="Theme.AndroidDevelopers" parent="android:style/Theme.Holo.Light">
    <item name="android:selectableItemBackground">@drawable/ad_selectable_background</item>
    <item name="android:popupMenuStyle">@style/MyPopupMenu</item>
    <item name="android:dropDownListViewStyle">@style/MyDropDownListView</item>
    <item name="android:actionBarTabStyle">@style/MyActionBarTabStyle</item>
    <item name="android:actionDropDownStyle">@style/MyDropDownNav</item>
    <item name="android:listChoiceIndicatorMultiple">@drawable/ad_btn_check_holo_light</item>
    <item name="android:listChoiceIndicatorSingle">@drawable/ad_btn_radio_holo_light</item>
</style>

更多信息: Android ActionBar

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM