顯示具有 CheckBox 標籤的文章。 顯示所有文章
顯示具有 CheckBox 標籤的文章。 顯示所有文章

2015年4月9日 星期四

Android CheckBox Text Up Left Right Bottom Location 核取方塊 文字位置

要改變checkbox的text位置需自訂圖片與選擇器
1.在/res/drawable/加入圖片checked.pngunchecked.png 


2./res/drawable/bottom.xml

    
    
        

3./res/layout/main.xml
android:button="@android:color/transparent" ----- 隱藏原核取方塊
android:drawableTop="@drawable/bottom" ----- 加入選擇器bottom.xml,文字在下方
android:drawableLeft ----- 文字在右方
android:drawableRight ----- 文字在左方
android:drawableBottom ----- 文字在上方


    

        
        
    

    

        
        
    

    

        
        
    

    

        
        
    


4.Main.java
package tw.android;

import android.app.Activity;
import android.os.Bundle;

public class Main extends Activity {

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

 }
 

}


參考來源:
http://stackoverflow.com/questions/27030629/android-how-to-align-the-checkbox-text-in-the-bottom
http://stackoverflow.com/questions/16063135/removing-the-box-from-the-checkbox-in-android

2014年5月28日 星期三

Android CheckBox

1.建立checkBox元件
activity_main.xml






2.建立字串
strings.xml
CheckMe

3.建立監聽事件 MainActivity.java
 private CheckBox checkBox1; //在onCreate上面先宣告
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  checkBox1 = (CheckBox) findViewById(R.id.checkBox1); //初始化,從activity_main.xml抓到id
  checkBox1.setChecked(true); //預設為以勾選,false為預設取消勾選
  checkBox1.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() { //建立監聽事件
  
   @Override
   public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
    // TODO Auto-generated method stub
    if (checkBox1.isChecked()) { //isChecked()判斷是否以勾選
     output.setText("以勾選"); //這裡如要帶入動作則要使用buttonView,ex:run(buttonView);
    } else {
     output.setText("取消勾選");
    }
   }
  
  });

 }