use*_*040 49 android button android-button
我试图在我的应用程序中设置按钮的背景颜色,我无法达到我想要的结果...
我试图设置的颜色是holo_green_light(#ff99cc00)
.为了做到这一点,我正在使用setColorFilter(0xff99cc00, PorterDuff.Mode.MULTIPLY);
我得到的颜色不仅仅是holo_green_light
lightgrey和holo_green_light
.
我尝试过使用LightingColorFilter
没有太大的成功.
有没有办法以编程方式进行,以便按钮看起来像一个按钮,而不是一个我需要的颜色的扁平矩形.
Beb*_*T.N 41
这是我用不同颜色做自定义Button的方法
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke android:width="3dp"
android:color="#80FFFFFF" />
<corners android:radius="25dp" />
<gradient android:angle="270"
android:centerColor="#90150517"
android:endColor="#90150517"
android:startColor="#90150517" />
</shape>
Run Code Online (Sandbox Code Playgroud)
这样你就可以设置为背景了.
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_marginBottom="25dp"
android:layout_centerInParent="true"
android:background="@drawable/button"/>
Run Code Online (Sandbox Code Playgroud)
小智 24
如果你想保持一般样式(圆角等)并只是改变背景颜色,那么我使用backgroundTint属性
android:backgroundTint="@android:color/holo_green_light"
Run Code Online (Sandbox Code Playgroud)
Ton*_*thy 18
按钮比仅改变一种颜色更复杂......
Android按钮是使用相当多的9补丁和状态drawables.您应该看一下Android Holo Colors来生成那些,您需要选择"Color Button",它会为您生成必要的图像和xml ...
V.N*_*ice 16
如果你不介意硬编码,你可以这样做〜> android:background ="#eeeeee"并删除你想要的任何十六进制颜色#.
看起来像这样....
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/textView1"
android:text="@string/ClickMe"
android:background="#fff"/>
Run Code Online (Sandbox Code Playgroud)
Gia*_*ant 13
/res/drawable/button.xml
使用以下内容创建 :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<!-- you can use any color you want I used here gray color-->
<solid android:color="#90EE90"/>
<corners
android:bottomRightRadius="3dp"
android:bottomLeftRadius="3dp"
android:topLeftRadius="3dp"
android:topRightRadius="3dp"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
然后您可以使用以下内容:
<Button
android:id="@+id/button_save_prefs"
android:text="@string/save"
android:background="@drawable/button"/>
Run Code Online (Sandbox Code Playgroud)
只需使用 aMaterialButton
和 app:backgroundTint
属性:
<MaterialButton
app:backgroundTint="@color/my_color_selector"
Run Code Online (Sandbox Code Playgroud)
尝试这个
<androidx.appcompat.widget.AppCompatButton
android:layout_width="wrap_content"
android:layout_height="34dp"
android:text="Check Out"
android:textAllCaps="true"
android:background="#54c2bc"
android:textColor="#FFFFFF"
android:textSize="9sp"/>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
157336 次 |
最近记录: |