如何为android指定背景正常颜色:attr/borderlessButtonStyle按钮
我想知道,我如何才能使用特定的背景正常颜色a如何为android指定背景正常颜色:attr/borderlessButtonStyle按钮,android,Android,我想知道,我如何才能使用特定的背景正常颜色a?安卓:attr/borderlessButtonStyle按钮 目前,我有以下按钮 <Button android:id="@+id/buy_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="?attr/shopButtonTextColor" style=
?安卓:attr/borderlessButtonStyle
按钮
目前,我有以下按钮
<Button
android:id="@+id/buy_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?attr/shopButtonTextColor"
style="?android:attr/borderlessButtonStyle"
android:textStyle="bold"
android:text="@string/shop_buy" />
填充/边距信息似乎消失了
当我按下它时,上一个涟漪选择器不见了
我想知道,我如何使用?android:attr/borderlessButtonStyle
,还能够实现以下功能
- 在
中保留填充/边距?安卓:attr/borderlessButtonStyle
- 保留
按钮的圆角(我猜是2dp)行为?android:attr/borderlessButtonStyle
- 在正常情况下,它有橙色背景
- 按下时,它在橙色背景的顶部有
(通常为灰色)彩色波纹覆盖colorControlHighlight
- 感谢@Vikram。通过使用以下技术,我能够实现一个漂亮的平面按钮效果,具有所需的背景颜色
<style name="ShopButton">
<item name="colorButtonNormal">@color/shop_button_background_color_material_light</item>
<item name="android:colorButtonNormal">@color/shop_button_background_color_material_light</item>
<item name="colorControlHighlight">@color/ripple_material_dark</item>
<item name="android:colorControlHighlight">@color/ripple_material_dark</item>
<item name="android:textColor">@color/shop_button_text_color_material_light</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">bold</item>
</style>
<Button
android:id="@+id/buy_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?attr/buttonStyle"
android:theme="@style/ShopButton"
android:stateListAnimator="@null"
android:text="@string/shop_buy" />
@颜色/店铺\按钮\背景\颜色\材料\灯光
@颜色/店铺\按钮\背景\颜色\材料\灯光
@颜色/波纹\u材质\u深色
@颜色/波纹\u材质\u深色
@颜色/店铺\按钮\文本\颜色\材料\灯光
16便士
大胆的
如下所示
根据您的描述,您需要
?attr/buttonStyle
而不是?attr/borderlessButtonStyle
。要获得橙色背景,请在应用程序的主题下覆盖colorButtonNormal
,并将其设置为所需的颜色。您应该设置android:stateListAnimator=“@null”
在您的按钮的
xml定义中。嗨,Vikram,您提出的解决方案对我来说非常有效-我唯一关心的是,让我的自定义按钮主题Shop.Button.Light
继承我的整个应用程序主题是否太“重”?这是一个好的做法吗?让我们在这里讨论一下:。
<style name="ShopButton">
<item name="colorButtonNormal">@color/shop_button_background_color_material_light</item>
<item name="android:colorButtonNormal">@color/shop_button_background_color_material_light</item>
<item name="colorControlHighlight">@color/ripple_material_dark</item>
<item name="android:colorControlHighlight">@color/ripple_material_dark</item>
<item name="android:textColor">@color/shop_button_text_color_material_light</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">bold</item>
</style>
<Button
android:id="@+id/buy_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?attr/buttonStyle"
android:theme="@style/ShopButton"
android:stateListAnimator="@null"
android:text="@string/shop_buy" />