【发布时间】:2016-09-25 09:20:39
【问题描述】:
我正在为 android 开发一个计算器应用程序,我使用可绘制文件来管理按钮集的颜色。 我需要允许用户通过提供几个可绘制文件来更改计算器主题,然后用户可以在它们之间进行选择。 除了制作多个布局之外,我不知道如何执行此操作,然后我可以在活动中使用 (if) 语句。 有没有简单的方法 我用这样的东西来定义按钮背景
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle" >
<corners android:radius="9dip" />
<stroke android:width="1dip" android:color="#009e9e9e" />
<gradient android:angle="-90" android:startColor="#ae104f" android:endColor="#8e0d40" />
</shape>
</item>
<item>
<layer-list>
<item android:right="5dp" android:top="5dp">
<shape>
<corners android:radius="8dp" />
<solid android:color="#bd848484" />
</shape>
</item>
<item android:bottom="1dp" android:left="2dp">
<shape>
<gradient android:angle="270"
android:endColor="#ae104f" android:startColor="#8e0d40" />
<stroke android:width="1dp" android:color="#BABABA" />
<corners android:radius="9dp" />
<padding android:bottom="10dp" android:left="10dp"
android:right="10dp" android:top="10dp" />
</shape>
</item>
</layer-list>
</item>
</selector>
谢谢
【问题讨论】:
-
您可以为每个主题使用颜色数组。看到这个stackoverflow.com/a/17584066/2058260
-
谢谢。但我使用可绘制文件来设置按钮背景(按钮具有渐变色)。我不知道在那里使用数组,但我会尝试。再次感谢。
-
你也可以为drawables做同样的创建数组stackoverflow.com/a/32829285/2058260
-
非常感谢,我想这就是我需要的。
标签: android android-theme xml-drawable