android - 抽屉导航改变颜色

标签 android android-layout navigation-drawer

我正在使用抽屉导航使用 this例子。我只想将蓝色更改为橙​​色,我该怎么做?我的意思是更改 ListView 选择器颜色,操作栏选择器颜色一切。

最佳答案

你可以使用选择器

在 drawable 文件夹中有如下的 selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" 
        android:drawable="@drawable/press" />
    <item  android:state_focused="false" 
        android:drawable="@drawable/normal" />
</selector>

在drawable文件夹下press.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#FF9D21"/>     
</shape>

在drawable文件夹下normal.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#8BC7EB"/>    
</shape>

在 drawer_list_item.xml 中

android:background="@drawable/selector"

为栏设计样式

  <resources>

    <!--
        Base application theme for API 11+. This theme completely replaces
        AppBaseTheme from res/values/styles.xml on API 11+ devices.
    -->
    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
         <item name="android:background">@style/MyActionBar</item>
        <!-- API 11 theme customizations can go here. -->
    </style>
    <style name="MyActionBar" parent="@android:style/Widget.Holo.ActionBar">
        <item name="android:background">@drawable/press</item>

    </style>
</resources>

在你的 list 中

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

您可以为特定 Activity 而不是整个应用程序指定主题。

更多信息

http://android-developers.blogspot.in/2011/04/customizing-action-bar.html

https://developer.android.com/training/basics/actionbar/styling.html

快照

enter image description here

关于android - 抽屉导航改变颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18759798/

相关文章:

android - Android SQL 如何从一列返回所有数据

java - 如何检查用户是否成功购买

android - 为什么以编程方式添加我的 TextView 时出现 NullPointerException?

android - 滑动抽屉位置在调整高度时发生变化

Android:如何在抽屉导航中实现设置页面?

android - 像 Google+ 一样的抽屉式导航

Android - 使 Activity 全屏并在其顶部显示状态栏

android - 按下硬件后退按钮时如何返回到上一个 fragment

android - 向 RelativeLayout 动态添加按钮无法正常工作

android - 带有导航项和普通项的抽屉导航