最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android開(kāi)發(fā)之開(kāi)關(guān)按鈕用法示例

 更新時(shí)間:2019年04月05日 08:44:56   作者:水中魚(yú)之1999  
這篇文章主要介紹了Android開(kāi)發(fā)之開(kāi)關(guān)按鈕用法,結(jié)合實(shí)例形式分析了Android開(kāi)關(guān)按鈕的具體實(shí)現(xiàn)、布局與功能設(shè)置相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Android開(kāi)發(fā)之開(kāi)關(guān)按鈕用法。分享給大家供大家參考,具體如下:

效果如下:

以下是布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/root"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical">
  <!--定義一個(gè)ToggleButton按鈕-->
  <ToggleButton
    android:id="@+id/toggle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textOff="橫向排列"
    android:textOn="縱向排列"
    android:checked="true"/>
  <Switch
    android:id="@+id/switcher"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textOff="橫向排列"
    android:textOn="縱向排列"
    android:thumb="@drawable/thumb"
    android:checked="true"/>
  <!--定義一個(gè)可以動(dòng)態(tài)改變方向的線性布局-->
  <LinearLayout
    android:id="@+id/text"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <Button
      android:id="@+id/button01"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" />
    <Button
      android:id="@+id/button02"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" />
    <Button
      android:id="@+id/button03"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" />
  </LinearLayout>
</LinearLayout>

活動(dòng)代碼實(shí)現(xiàn):

public class Home extends AppCompatActivity {
  ToggleButton toggle ;
  Switch switcher ;
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);//顯示manLayout
    toggle = (ToggleButton) findViewById(R.id.toggle);
    switcher = (Switch) findViewById(R.id.switcher);
    final LinearLayout text = (LinearLayout) findViewById(R.id.text);
    CompoundButton.OnCheckedChangeListener onCheckedChangeListener =
        new CompoundButton.OnCheckedChangeListener() {
      @Override
      public void onCheckedChanged(
          CompoundButton buttonView, boolean isChecked) {
        if (isChecked) {
          //設(shè)置LinearLayout垂直布局
          text.setOrientation(LinearLayout.VERTICAL);
          toggle.setChecked(true);
          switcher.setChecked(true);
        }else {
          //設(shè)置水平布局
          text.setOrientation(LinearLayout.HORIZONTAL);
          toggle.setChecked(false);
          switcher.setChecked(false);
        }
      }
    };
    toggle.setOnCheckedChangeListener(onCheckedChangeListener);
    switcher.setOnCheckedChangeListener(onCheckedChangeListener);
  }
}

其中switch組建的 thumb:@drawable/thumb項(xiàng)參考自://m.fzitv.net/article/159100.htm

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android控件用法總結(jié)》、《Android開(kāi)發(fā)入門與進(jìn)階教程》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android數(shù)據(jù)庫(kù)操作技巧總結(jié)》及《Android資源操作技巧匯總

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

色达县| 云阳县| 庄河市| 淳化县| 玉林市| 视频| 乌拉特后旗| 南澳县| 阿合奇县| 蛟河市| 于田县| 彝良县| 元谋县| 宁阳县| 沈阳市| 蕉岭县| 仪陇县| 武胜县| 增城市| 始兴县| 伊宁市| 清远市| 沙洋县| 岑溪市| 神池县| 海伦市| 武清区| 达孜县| 固安县| 安乡县| 会泽县| 武陟县| 普格县| 包头市| 彝良县| 株洲市| 巴彦淖尔市| 扶余县| 招远市| 双流县| 金堂县|