[英]I have two button for which i create the XML to make buttons round.But I want to give the different color to both button
在這里,我正在編寫XML代碼,我正在使用它來更改按鈕的背景。
roundbutton2.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#eea0e5ee"/>
<corners android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topRightRadius="10dp"
android:topLeftRadius="10dp"/>
</shape>
按鈕片段
<Button
android:layout_width="125dp"
android:layout_height="55dp"
android:text="Clear"
android:id="@+id/bt_clear"
android:layout_marginLeft="55dp"
android:layout_marginRight="30dp"
android:textColor="#FFFFFF"
android:textSize="25dp"
android:textAllCaps="false"
android:background = "@drawable/roundbutton2"/>
<Button
android:layout_width="125dp"
android:layout_height="55dp"
android:text="Proceed"
android:textColor="#FFFFFF"
android:textSize="25dp"
android:id="@+id/bt_proceed"
android:textAllCaps="false"
android:background = "@drawable/roundbutton2"/>
首先,我需要#EE494D4E顏色和第二個按鈕,我想要#eea0e5ee。如何做到這一點。 我想要使用相同XML文件的兩個按鈕的不同顏色。 請告訴我這件事。謝謝
在你的roundbutton2.xml
你直接將形狀值的顏色設置為#eea0e5ee
,這會使你的按鈕將其設置為背景以獲得該顏色。 我做的是刪除<solid android:color="#eea0e5ee"/>
並通過xml將backgroundTint
設置為您喜歡的顏色,如下所示:
<Button
android:id="@+id/bt_clear"
android:layout_width="125dp"
android:layout_height="55dp"
android:layout_marginLeft="55dp"
android:layout_marginRight="30dp"
android:background="@drawable/roundbutton2"
android:backgroundTint="#EE494D4E"
android:text="Clear"
android:textAllCaps="false"
android:textColor="#FFFFFF"
android:textSize="25dp" />
<Button
android:id="@+id/bt_proceed"
android:layout_width="125dp"
android:layout_height="55dp"
android:background="@drawable/roundbutton2"
android:backgroundTint="#eea0e5ee"
android:text="Proceed"
android:textAllCaps="false"
android:textColor="#FFFFFF"
android:textSize="25dp" />
注意 :這只是一種解決方法。 我不完全確定是否應該這樣做,或者是否違反最佳做法。 這個答案在這里是我的參考。 如果您仍希望保留按鈕的默認顏色值,則可以通過編程方式實現更改其他按鈕顏色的唯一方法。
干杯! :d
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.