android - 如何改变主题的触摸高亮颜色?
怪我咯
怪我咯 2017-04-17 11:29:38
[Android讨论组]

我想要替代或者覆盖主题的默认触摸高亮颜色,目前,使用actionBarItemBackground已经成功地更改了主题栏按钮的高亮颜色。但是,我在寻找一种应用程序范围变化的幅度,保证在按下按钮,动作条,抽屉或菜单时,会显示我所设置的默认颜色。我尝试设置colorPressedHighlight.和colorFocusedHighlight的属性,但是不起作用。我也想要改变,滚动条滚动到底时的提示颜色,以及想要继续下拉的渐变色。该怎么解决呢?

原问题:Override theme color for touch highlight, scroll hinting

怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复(1)
怪我咯

答:Manu Zi
你可以下载这个软件,然后装到应用上,这样就可以改变主题风格了。http://android-holo-colors.com/

答:Kevin van Mierlo
我相信,下述方法会对你有帮助,它主要是通过设置应用中的可选择项目的背景颜色,完成触摸高亮颜色的改变:

<style name="Theme.Holo">
    <!-- bunch of things -->
    <item name="android:selectableItemBackground">@android:drawable/item_background_holo_dark</item>
    <!-- bunch of things -->
</style>

它的drawable XML是:

<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
<item android:state_focused="true"  android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/list_selector_disabled_holo_dark" />
<item android:state_focused="true"  android:state_enabled="false"                              android:drawable="@drawable/list_selector_disabled_holo_dark" />
<item android:state_focused="true"                                android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition_holo_dark" />
<item android:state_focused="false"                               android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition_holo_dark" />
<item android:state_focused="true"                                                             android:drawable="@drawable/list_focused_holo" />
<item                                                                                          android:drawable="@color/transparent" />

答:KBusc
你是要在应用的drawable文件夹中添加一个custom_color.xml文件,因此你可以按照自己的需求将其命名:

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
    <shape>
        <gradient
            android:startColor="#004F81"
            android:endColor="#004F81"
            android:angle="270" />
        <stroke
            android:width="3dp"
            android:color="#004F81" />
        <corners
            android:radius="3dp" />          
    </shape>
</item>
<item android:state_focused="true" >
    <shape>
        <gradient
            android:endColor="#004F81"
            android:startColor="#004F81"
            android:angle="270" />
        <stroke
            android:width="3dp"
            android:color="#004F81" />
        <corners
            android:radius="3dp" />         
    </shape>
</item>
<item>        
    <shape>
        <gradient
            android:endColor="#43AFE8"
            android:startColor="#43AFE8"
            android:angle="270" />
        <stroke
            android:width="1dp"
            android:color="#43AFE8" />
        <corners
            android:radius="6dp" />
        <padding
            android:left="2dp"
            android:top="2dp"
            android:right="2dp"
            android:bottom="2dp" />
    </shape>
</item>
</selector>

然后在所有的layout xml文件中,再设置每个元素的背景即可:

<Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/custom_color"
        android:textColor="#FFFFFF"
        android:text="Button" />

实践证明,这种代码工作效果不错。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号