相关疑难解决方法(0)

使用Material Design和AppCompat的Android中的着色按钮

AppCompat今天发布更新之前,我能够更改Android L中按钮的颜色,但不能更改旧版本.包含新的AppCompat更新后,我无法更改任何一个版本的颜色,当我尝试按钮时就消失了.有谁知道如何更改按钮颜色?

以下图片显示了我想要实现的目标:

显示所需结果的图片

白色按钮是默认的,红色按钮是我想要的.

这是我之前做的改变以下按钮颜色的方法styles.xml:

<item name="android:colorButtonNormal">insert color here</item>
Run Code Online (Sandbox Code Playgroud)

并动态地做:

button.getBackground().setColorFilter(getResources().getColor(insert color here), PorterDuff.Mode.MULTIPLY);
Run Code Online (Sandbox Code Playgroud)

我也确实将主题父@android:style/Theme.Material.Light.DarkActionBar改为Theme.AppCompat.Light.DarkActionBar

android button android-button android-view material-design

245
推荐指数
8
解决办法
17万
查看次数

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

我使用的是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万
查看次数