相关疑难解决方法(0)

标准Android按钮具有不同的颜色

我想稍微更改标准Android按钮的颜色,以便更好地匹配客户的品牌.

到目前为止,我发现这样做的最好方法是将Button'drawable'改为drawable,位于res/drawable/red_button.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/red_button_pressed" />
    <item android:state_focused="true" android:drawable="@drawable/red_button_focus" />
    <item android:drawable="@drawable/red_button_rest" />
</selector>
Run Code Online (Sandbox Code Playgroud)

但这样做需要我居然为每一个按钮,我想自定义三种不同的可绘制(一个用于按钮在休息,一个集中的时候,和一个按下时).这似乎比我需要的更复杂,更干燥.

我真正想做的就是对按钮应用某种颜色转换.是否有更简单的方法来改变按钮的颜色而不是我正在做的事情?

android android-layout

728
推荐指数
12
解决办法
47万
查看次数

对按钮的物质作用有背景颜色的

我使用的是Android v21支持库.

我创建了一个自定义背景颜色的按钮.当我使用背景颜色时,材质设计效果如波纹,显示消失(除了点击的高度).

 <Button
 style="?android:attr/buttonStyleSmall"
 android:background="?attr/colorPrimary"
 android:textColor="@color/white"
 android:textAllCaps="true"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text="Button1"
 />
Run Code Online (Sandbox Code Playgroud)

背景 以下是一个普通的按钮,效果很好.

<Button
 style="?android:attr/buttonStyleSmall"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:textAllCaps="true"
 android:text="Button1"
/>
Run Code Online (Sandbox Code Playgroud)

默认按钮

android android-5.0-lollipop

238
推荐指数
11
解决办法
21万
查看次数

单击时如何在Android中更改按钮的颜色?

我正在开发Android应用程序.我想让4个按钮水平放置在屏幕的底部.在这4个按钮中,2个按钮上有图像.按钮的边框应为黑色,边框应尽可能薄.当我单击按钮时,我希望按钮的背景应该更改为蓝色而不更改边框的颜色,并且应该保留该颜色一段时间.如何在Android中实现此方案?

android

75
推荐指数
7
解决办法
25万
查看次数

选择器资源可以使用样式中定义的颜色吗?

我正在尝试使用选择器中stlyle中定义的颜色,但它导致了一个Resources $ NotFoundException.

首先,我向attr.xml添加了一个新属性:

<resources>
    <attr name="unread_background" format="color" />
</resources>
Run Code Online (Sandbox Code Playgroud)

然后我在styles.xml中定义了attr值:

<style name="ThemeNoTitleBar" parent="android:Theme.NoTitleBar">
    <item name="unread_background">#000000</item>
</style>
Run Code Online (Sandbox Code Playgroud)

然后我尝试在我的选择器定义中使用该attr:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- other states snipped -->
    <item android:state_selected="false"
        android:drawable="?unread_background" />
</selector>
Run Code Online (Sandbox Code Playgroud)

最后,活动在清单中使用ThemeNoTitleBar样式主题.

我也尝试在colors.xml中创建一个颜色并让它使用新的attr,但也失败了.

我显然错过了一些东西,但我不知道该怎么做才能修复它.我的目的是创建多个主题,并让选择器使用当前所选主题中的颜色.

android

16
推荐指数
1
解决办法
4511
查看次数