我使用的是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)

我从XML获得了一个视图,其代码如下:
Button view = (Button) LayoutInflater.from(this).inflate(R.layout.section_button, null);
Run Code Online (Sandbox Code Playgroud)
我想为按钮设置一个"样式"我怎么能在java中这样做,因为我想使用几个样式我将使用的每个按钮.
我使用这种风格来改变我的背景颜色Button:
<style name="AccentButton" parent="Widget.AppCompat.Button.Colored">
<item name="colorButtonNormal">@color/colorAccent</item>
<item name="android:textColor">@color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)
在布局中:
<Button
android:id="@+id/login_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/fragment_login_login_button"
app:theme="@style/AccentButton"/>
Run Code Online (Sandbox Code Playgroud)
有用.但是当我打电话setEnabled(false)给它时Button,它保持相同的颜色.我该如何处理这个案子?
我试图保持棒棒糖及以上(21+)设备的材料设计波纹效果,并对按钮进行风格化,使其周围没有大的边距/空间.
示例1:具有连锁效应但具有边距/间隙的按钮:

示例2:没有波纹效应且没有边距/间隙的按钮:

我希望Exmaple 2的布局具有示例1中使用的涟漪效应.
我styles-v21对实例1的看法如何:
<?xml version="1.0" encoding="utf-8"?>
<resources>
... other styles ...
<style name="FacebookButton" parent="android:Widget.Material.Button">
<item name="android:colorButtonNormal">#ff3b5998</item>
<item name="android:layout_margin">0dp</item>
<item name="android:borderlessButtonStyle">@style/Widget.AppCompat.Button.Borderless</item>
</style>
<style name="GoogleButton" parent="android:Widget.Material.Button">
<item name="android:colorButtonNormal">#ffdd4b39</item>
<item name="android:layout_margin">0dp</item>
<item name="android:borderlessButtonStyle">@style/Widget.AppCompat.Button.Borderless</item>
</style>
<style name="TwitterButton" parent="android:Widget.Material.Button">
<item name="android:colorButtonNormal">#ff55acee</item>
<item name="android:layout_margin">0dp</item>
<item name="android:borderlessButtonStyle">@style/Widget.AppCompat.Button.Borderless</item>
</style>
<style name="SkipButton" parent="android:Widget.Material.Button">
<item name="android:colorButtonNormal">#ffdfa800</item>
<item name="android:layout_margin">0dp</item>
<item name="android:borderlessButtonStyle">@style/Widget.AppCompat.Button.Borderless</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
示例1的按钮布局是什么样的:
<Button
android:id="@+id/login_with_facebook"
android:text="@string/login_with_facebook"
android:fontFamily="sans-serif-condensed"
android:textSize="16sp"
android:drawableLeft="@drawable/facebook_icon"
android:drawablePadding="25dp"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_weight="16.88"
android:textColor="#ffffff"
android:gravity="left|center_vertical"
android:paddingLeft="45dp" …Run Code Online (Sandbox Code Playgroud) android android-theme android-button material-design android-5.0-lollipop
我在这里看到了新的appCompat控件.并在Android应用程序中实现它,但我没有找到任何特定的方式来自定义其颜色.
就像我们在样式中设置强调色一样,编辑文本会自动捕获它.但它在AppCompatButton的情况下不起作用.
有没有人发现这件事?
我有以下对话框
它是使用以下代码创建的
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Random random = new Random();
// 0 or 1.
final int value = random.nextInt(2);
final int title = R.string.we_love_you_0;
final int content = R.string.rate_us_with_5_stars_review_0;
final AlertDialog dialog = new AlertDialog.Builder(this.getActivity())
.setTitle(title)
.setMessage(content)
// Add action buttons
.setPositiveButton(R.string.rate_5_stars, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
}
})
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
})
.setNeutralButton(R.string.later, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int …Run Code Online (Sandbox Code Playgroud) 我需要知道使用最新的AppCompat(暂时为23.2.1)对材质按钮(AppCompatButton)进行着色的最佳(和推荐)方法是什么.我原本无法想象它会如此令人沮丧!我从这里尝试了大部分答案,但要么它们不起作用,要么与意想不到的结果一起工作.
我需要保持向后兼容api> = 9并且只需要将涟漪效应应用于> = 21没什么特别的.那么到目前为止最好的方法是什么?
如果你能同时提供xml和java代码,我将不胜感激.