Android:不改变背景颜色的圆形按钮角落

问题描述:

好的,所以我知道如何在android中使用可绘制背景将角落倒圆角。问题是,这是否也需要我手动设置按钮的颜色。如何在保持按钮主题颜色的同时更改角部半径?Android:不改变背景颜色的圆形按钮角落

round_button.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android"> 
    <corners android:radius="40dp" /> 
    <solid android:color="#80000000" /> 
</shape> 

在activity_main.xml中

<Button 
    android:id="@+id/button2" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_column="1" 
    android:layout_columnSpan="1" 
    android:layout_columnWeight="1" 
    android:layout_row="0" 
    android:background="@drawable/round_button" 
    android:text="Button" /> 

我只想主题颜色仍然被应用到按钮上,但能也圆角落更多。

+1

你能用一个例子或代码描述你的问题吗? –

+0

@ANUJGUPTA我添加了一些代码 –

尝试将按钮的颜色设置为透明,您需要设置颜色,这样您可以保留主题颜色。

+0

这只是将按钮颜色设置为黑色 –

我设法让使用该按钮的代表色,以解决这个问题:

<?xml version="1.0" encoding="utf-8"?> 
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android"> 
    <corners android:radius="40dp" /> 
    <solid android:color="?android:colorButtonNormal" /> 
</shape> 

应用色彩到按钮所需的颜色。

button.setColorFilter(ContextCompat.getColor(context, R.color.COLOR_YOUR_COLOR), android.graphics.PorterDuff.Mode.REQUIRED_MODE);