簡體   English   中英

Android操作欄,更改顏色並添加搜索功能

[英]Android action bar, Change color and add search function

您能幫助我如何更改操作欄的顏色以及如何添加搜索功能(ic_search菜單)

我正在使用API​​ 14,並且我的項目還附加了庫v7

我已經嘗試過這種顏色了,但是不起作用? 我的風格文件

<resources>

    <!--
        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="Theme.AppCompat.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. -->
        <item name="android:windowFullscreen">true</item>
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>






        <!-- ActionBar styles -->
        <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
             <item name="android:background">@color/orange_dark</item>
        </style>



</resources>

我的清單:

  <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="21" />


    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera" />


    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" android:name=".gears.MyApplication">

        <activity
            android:name=".SplashScreen"
            android:label="@string/title_activity_splash_screen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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


        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
        </activity>





    </application>

</manifest>

為了更改顏色,您應該在values文件夾中創建一個styles.xml,如下所示:

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

         <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
           parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
        <!-- Support library compatibility -->
        <item name="actionBarStyle">@style/MyActionBar</item>
    </style>

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

        <!-- Support library compatibility -->
        <item name="background">@color/action_bar</item>
        <item name="backgroundSplit">@color/action_bar</item>
    </style>



</resources>

然后在清單文件中的應用程序標記或活動標記中添加自定義主題:

<application
android:name=".MendiLineApplication"
android:allowBackup="true"
android:icon="@drawable/blue_mountain_b"
android:label="@string/app_name"
android:theme="@style/CustomActionBarTheme" >

要將搜索圖標添加為操作,請在菜單配置文件(menu.xml)中添加一個項目:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/search"
        android:icon="@drawable/ic_action_search"
          android:title="Search"
          android:showAsAction="ifRoom"
    />
</menu>

暫無
暫無

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

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