欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

android基本控件ToggleButton&Switch使用指南

 更新時(shí)間:2016年01月09日 08:46:56   投稿:hebedich  
本文給大家匯總介紹了android的2個(gè)基本控件ToggleButton和Switch的使用方法,非常的詳細(xì),有需要的小伙伴可以參考下。

ToggleButton(開關(guān)按鈕)和Switch(開關(guān))講解:

一、核心屬性講解:

(1)ToggleButton

textOn:按鈕被選中的時(shí)候文字顯示

textOff:按鈕沒有被選中的時(shí)候文字顯示

ToggleButton的狀態(tài)只能是選中和未選中,并且需要為不同的狀態(tài)設(shè)置不同的顯示文本。

以下案例為ToggleButton的用法

目錄結(jié)構(gòu)

main.xml布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <ImageView android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/bulb_off" 
    android:layout_gravity="center_horizontal" />
  <ToggleButton android:id="@+id/toggleButton"
    android:layout_width="140dip"
    android:layout_height="wrap_content"
    android:textOn="開燈"
    android:textOff="關(guān)燈"
    android:layout_gravity="center_horizontal" />
</LinearLayout>

ToggleButtonActivity類

package com.ljq.tb;

import android.app.Activity;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.ToggleButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

public class ToggleButtonActivity extends Activity {
  private ImageView imageView=null;
  private ToggleButton toggleButton=null;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    
    imageView=(ImageView) findViewById(R.id.imageView);
    toggleButton=(ToggleButton)findViewById(R.id.toggleButton);
    toggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener(){

      public void onCheckedChanged(CompoundButton buttonView,
          boolean isChecked) {
        toggleButton.setChecked(isChecked);
        imageView.setImageResource(isChecked?R.drawable.bulb_on:R.drawable.bulb_off);
      }
      
    });
  }
}

運(yùn)行效果:

(2)switch:

showText:設(shè)置textOn/off的時(shí)候文字是否顯示

android:showText:設(shè)置on/off的時(shí)候是否顯示文字,boolean

android:splitTrack:是否設(shè)置一個(gè)間隙,讓滑塊與底部圖片分隔,boolean

android:switchMinWidth:設(shè)置開關(guān)的最小寬度

android:switchPadding:設(shè)置滑塊內(nèi)文字的間隔

android:textOff:按鈕沒有被選中時(shí)顯示的文字

android:textOn:按鈕被選中時(shí)顯示的文字

android:textStyle:文字風(fēng)格,粗體,斜體寫劃線那些

android:track:底部的圖片

android:thumb:滑塊的圖片

可以自己動(dòng)手試一試每一個(gè)屬性

在做一個(gè)藍(lán)牙開關(guān)時(shí)候,用到了switch,記一下用法,其實(shí)跟Button是幾乎一樣的.

布局中:

<Switch 
    android:id="@+id/open" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textOff="藍(lán)牙關(guān)閉中" 
    android:textOn="藍(lán)牙開啟中" /> 


java代碼中

open.setOnCheckedChangeListener(new OnCheckedChangeListener() { 
 
      @Override 
      public void onCheckedChanged(CompoundButton buttonView, 
          boolean isChecked) { 
        // TODO Auto-generated method stub 
        if (isChecked) { 
          mBluetoothAdapter.enable();//打開藍(lán)牙 
        } else { 
          mBluetoothAdapter.disable();// 關(guān)閉藍(lán)牙 
        } 
      } 
    }); 

就是這樣了,一看就明白了.

相關(guān)文章

  • Android實(shí)現(xiàn)個(gè)人資料頁面頭像背景模糊顯示包(狀態(tài)欄)

    Android實(shí)現(xiàn)個(gè)人資料頁面頭像背景模糊顯示包(狀態(tài)欄)

    這篇文章主要介紹了Android實(shí)現(xiàn)個(gè)人資料頁面頭像背景模糊顯示包括狀態(tài)欄,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2017-03-03
  • AndroidManifest.xml uses-feature功能詳解

    AndroidManifest.xml uses-feature功能詳解

    這篇文章主要介紹了AndroidManifest.xml uses-feature功能,較為詳細(xì)的分析了Android屬性過濾操作的功能與相關(guān)技巧,需要的朋友可以參考下
    2016-10-10
  • 淺析Android 快速實(shí)現(xiàn)圖片壓縮與上傳功能

    淺析Android 快速實(shí)現(xiàn)圖片壓縮與上傳功能

    在Android對(duì)手機(jī)相冊中的圖片的壓縮和上傳到服務(wù)器上,這樣的功能在每個(gè)app開發(fā)中都會(huì)有這樣的需求.所以今天就對(duì)android端怎么快速實(shí)現(xiàn)圖片壓縮和上傳進(jìn)行簡單的分析
    2017-08-08
  • Android數(shù)據(jù)轉(zhuǎn)移之Launcher導(dǎo)出數(shù)據(jù)庫給另一臺(tái)機(jī)器加載

    Android數(shù)據(jù)轉(zhuǎn)移之Launcher導(dǎo)出數(shù)據(jù)庫給另一臺(tái)機(jī)器加載

    這篇文章主要介紹了Android系統(tǒng)中Launcher導(dǎo)出數(shù)據(jù)庫給另一臺(tái)機(jī)器加載的詳細(xì)流程,數(shù)據(jù)轉(zhuǎn)移是少見但早晚要用到的功能,感興趣的朋友快來提前掌握吧
    2021-11-11
  • Android?NDK開發(fā)(C語言--聯(lián)合體與枚舉)

    Android?NDK開發(fā)(C語言--聯(lián)合體與枚舉)

    這篇文章主要介紹了Android?NDK開發(fā)C語言聯(lián)合體與枚舉,共用體是一種特殊的數(shù)據(jù)類型,允許您在相同的內(nèi)存位置存儲(chǔ)不同的數(shù)據(jù)類型。您可以定義一個(gè)帶有多成員的共用體,但是任何時(shí)候只能有一個(gè)成員帶有值。下面詳細(xì)介紹該內(nèi)容,需要的朋友可以參考一下
    2021-12-12
  • Android 如何采用Lame編碼器編碼mp3文件

    Android 如何采用Lame編碼器編碼mp3文件

    這篇文章主要介紹了Android 如何采用Lame編碼器編碼mp3文件,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下
    2021-03-03
  • Android繪圖之Paint的使用方法詳解

    Android繪圖之Paint的使用方法詳解

    這篇文章主要給大家介紹了關(guān)于Android繪圖之Paint使用的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),并給大家介紹了DrawText 基線確定的方法,需要的朋友可以參考借鑒,下面隨著小編來一些學(xué)習(xí)學(xué)習(xí)吧。
    2017-11-11
  • Android實(shí)現(xiàn)掃描和生成二維碼

    Android實(shí)現(xiàn)掃描和生成二維碼

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)掃描和生成二維碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-05-05
  • Android實(shí)現(xiàn)二級(jí)列表購物車功能

    Android實(shí)現(xiàn)二級(jí)列表購物車功能

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)二級(jí)列表購物車功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • Android6.0開發(fā)中屏幕旋轉(zhuǎn)原理與流程分析

    Android6.0開發(fā)中屏幕旋轉(zhuǎn)原理與流程分析

    這篇文章主要介紹了Android6.0開發(fā)中屏幕旋轉(zhuǎn)原理與流程,結(jié)合實(shí)例形式詳細(xì)分析了Android6.0屏幕旋轉(zhuǎn)的原理與相關(guān)實(shí)現(xiàn)流程,并附帶了Android動(dòng)態(tài)開啟與禁用屏幕旋轉(zhuǎn)的實(shí)現(xiàn)方法,需要的朋友可以參考下
    2017-11-11

最新評(píng)論