[英]Android. How to show circle of radio button
我需要以編程方式隱藏和顯示單選按鈕圈。 這是我的代碼:
private fun hideCircle() {
rbTest.buttonDrawable = null
rbTest.isClickable = false
}
如何用圓圈返回單選按鈕的先前外觀。 我有一個解決方案,但它適用於 23 api:
private var drawable: Drawable? = null
drawable = rbTest.buttonDrawable
private fun showCircle() {
rbTest.buttonDrawable = drawable
rbTest.isClickable = true
}
但我需要從 19 api 開始執行此操作。 請幫我。
嘗試像這樣為單選按鈕創建一個可繪制對象。 您可以編輯此可繪制對象以適合您的規格。
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="3dp"
android:left="3dp"
android:right="3dp"
android:top="1dp">
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_radio_button_checked_24dp" android:state_checked="true" >
</item>
<item android:drawable="@drawable/ic_radio_button_unchecked_24dp" android:state_checked="false">
</item>
</selector>
</item>
</layer-list>
然后以編程方式 int 你的 Activity 做
RadioButton radioButton = new RadioButton(this);
radioButton.setButtonDrawable(R.drawable.radio_button);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.