【发布时间】:2013-09-12 08:57:23
【问题描述】:
我正在使用this 示例使用导航抽屉。我只想将蓝色更改为橙色,我该怎么做?我的意思是改变列表视图选择器颜色,操作栏选择器颜色一切。
【问题讨论】:
标签: android android-layout navigation-drawer
我正在使用this 示例使用导航抽屉。我只想将蓝色更改为橙色,我该怎么做?我的意思是改变列表视图选择器颜色,操作栏选择器颜色一切。
【问题讨论】:
标签: android android-layout navigation-drawer
你可以使用选择器
在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文件夹中按.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FF9D21"/>
</shape>
在可绘制文件夹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>
在您的清单中
<activity
android:name=".MainActivity"
android:theme="@style/MyActionBar"
android:label="@string/app_name">
您可以为特定活动而不是整个应用程序指定主题。
更多信息
http://android-developers.blogspot.in/2011/04/customizing-action-bar.html
https://developer.android.com/training/basics/actionbar/styling.html
快照
【讨论】:
android:layout_height="" 和android:layout_width="" 属性,否则Android Studio/Gradle 将无法编译您的应用
你必须为此做两件事。
【讨论】:
试试这个代码,
mDrawerLayout.setBackgroundResource(int);
【讨论】:
您需要使用选择器。
查看本教程了解更多信息。 customizing listviews
【讨论】:
对于ActionBar backgroownd:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:actionBarItemBackground">@drawable/bg_actionbar</item>
</style>
</resources>
【讨论】:
我想为@Raghunandan 给出的答案做出贡献。在列表中,您可以区分单击的项目(android:state_pressed)和激活的项目(android:state_activated),因此,如果您单击列表中已激活的项目,则单击是可视化的。
在drawable文件夹下创建一个activated.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#6A6A6A"/>
</shape>
并修改 selector.xml 添加 state_activated 修饰符:
<?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_activated="true"
android:drawable="@drawable/activated" />
<item android:state_focused="false"
android:drawable="@drawable/normal" />
</selector>
【讨论】:
使用选择器来实现这一点。您可以使用@drawable 或@color。
item android:drawable="@drawable/list_item_bg_pressed" android:state_pressed="true"/>
item android:drawable="@drawable/list_item_bg_normal" android:state_activated="false"/>
item android:drawable="@drawable/list_item_bg_selected" android:state_activated="true"/
【讨论】: