我試圖在Button中設定漸變色(在android studio中,其版本為Arctic Fox)。
gradientbuttonmainactivity.xml 我在Drawable中制作了這個檔案。
<?xml version="1.0" encoding="utf-8"? >
<shape。
xmlns:android="http://schemas.android.com/apk/res/android"/span>
android:shape="rectangle">>
<gradient
android:startColor="#93501C"/span>
android:endColor="#A67E7E"。
android:type="linear"/span>
android:angle="360"/span>/>
<corners
android:radius="25dp"/span>/>
</shape>/span>
activity_main.xml
<Button
android:id="@ id/btnR"/span>
android:layout_width="275dp"/span>
android:layout_height="55dp"/span>
android:layout_marginStart="55dp"/span>
android:layout_marginTop="25dp"/span>
android:background="@drawable/gradientbuttonmainctivity"
android:text="@string/register" />
但按鈕的顏色和原來一樣,角值被應用,但漸變值沒有。
我在谷歌上搜索了一下,但沒有找到任何有效的解決方案。
在一個stackoverflow的答案中,一個作者說要用@null改變colorPrimary(在theme.xml中)。我這樣做了,并且應用了漸變色,但在運行時,應用程式未能在智能手機中打開,然而它卻成功啟動了。
因此,我的問題很清楚,我如何使按鈕具有漸變的顏色?謝謝你。
uj5u.com熱心網友回復:
作為一個替代方案,請嘗試使用
androidx.appcompat.widget.AppCompatButton
代替
Button
這可能是Button和Android的材料設計最近發生的變化,我注意到在較早的專案中,你所實施的Button可以使用,但在較近的專案中,該背景不作業
。轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/313055.html
標籤:
