Android中代碼設置RadioButton的高端技巧


不知道怎么起標題,就這樣了。

 

目前主要講兩個方面內容:

  1. 代碼方式 設置RadioButton的 android:buttonandroid:background 等屬性為 @null ;
  2. 代碼方式 通過布局模板動態創建固定參數的RadioButton等控件對象

 

1、代碼設置@null

// 這里不能用null,必需采用以下方式設置
radioButton.setButtonDrawable(getResources().getDrawable(android.R.color.transparent));

// 對於background則可以簡單使用null
radioButton.setBackground(null);

 


 

2、通過布局模板創建控件對象

先創建包含所有默認參數的單個控件布局xml腳本模板,這里跟創建ListView使用的item布局腳本是差不多的東西

<?xml version="1.0" encoding="utf-8"?>
<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:background="@null"
    android:button="@null"
    android:drawablePadding="-20dp"
    android:drawableTop="@drawable/cat" />

 

通過代碼引入上面的模板,創建新對象

RadioButton radioButton = (RadioButton) getLayoutInflater().inflate(R.layout.radiobutton, null);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM