我在 xml 中有一個使用 <shape> 的自定義可繪制物件,代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/blue"/>
<corners
android:radius="150dp"/>
</shape>
在一個按鈕上,我想以編程方式將按鈕的顏色更改為另一種顏色,同時保持它從自定義可繪制物件獲得的形狀。這可能嗎?
uj5u.com熱心網友回復:
如果您不想在 xml 檔案夾中使用正常的 backgrounTint:
android:backgroundTint="yourcolor"
在您的 java 代碼中使用此代碼:
yourbutton.setBackgroundTintList(this.getResources().getColorStateList(R.color.colorname));
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/469552.html
上一篇:如何僅使用curl在ArtifactoryRepo子檔案夾中搜索
下一篇:兩個lib-gdx維度中的重力
