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

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)參考自://www.dbjr.com.cn/article/159100.htm

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

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

相關(guān)文章

  • Android ListView獲得選項(xiàng)中的值

    Android ListView獲得選項(xiàng)中的值

    本篇文章主要介紹Android ListView,在Android開(kāi)發(fā)過(guò)程中經(jīng)常會(huì)用到ListView 組件并有監(jiān)聽(tīng)事件,這里給大家一個(gè)簡(jiǎn)單實(shí)例,來(lái)說(shuō)明如何得到ListView選項(xiàng)中的值
    2016-07-07
  • Android的HTTP多線程下載示例代碼

    Android的HTTP多線程下載示例代碼

    本篇文章主要介紹了Android的HTTP多線程下載示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-03-03
  • java實(shí)現(xiàn)靜默安裝apk

    java實(shí)現(xiàn)靜默安裝apk

    本文給大家分享的是如何實(shí)現(xiàn)偷偷的把一個(gè)安卓apk應(yīng)用安裝到手機(jī)上,而且不顯示確認(rèn)框,主要是通過(guò)反射來(lái)實(shí)現(xiàn),好了,小伙伴們仔細(xì)看下代碼吧,有需要的小伙伴可以參考下。
    2015-04-04
  • Android實(shí)現(xiàn)音量調(diào)節(jié)的方法

    Android實(shí)現(xiàn)音量調(diào)節(jié)的方法

    這篇文章主要介紹了Android實(shí)現(xiàn)音量調(diào)節(jié)的方法,涉及Android頁(yè)面布局及多媒體播放的設(shè)置技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-09-09
  • android自定義彈出框樣式的實(shí)現(xiàn)方法

    android自定義彈出框樣式的實(shí)現(xiàn)方法

    這篇文章主要為大家詳細(xì)介紹了android自定義彈出框樣式的實(shí)現(xiàn)方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-05-05
  • 解決Android SELinux權(quán)限問(wèn)題記錄分析

    解決Android SELinux權(quán)限問(wèn)題記錄分析

    這篇文章主要為大家介紹了解決Android SELinux權(quán)限問(wèn)題記錄分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-11-11
  • Android啟動(dòng)相機(jī)拍照并返回圖片

    Android啟動(dòng)相機(jī)拍照并返回圖片

    Android啟動(dòng)相機(jī)拍照并返回圖片,事先定義拍照方法,在啟動(dòng)拍照之前先判斷內(nèi)存是否可用,通過(guò)重寫(xiě)onactivityresult()方法,獲取拍好的圖片。對(duì)下文感興趣的朋友可以參考下
    2015-10-10
  • 詳解 Kotlin Reference  Basic Types, String, Array and Imports

    詳解 Kotlin Reference Basic Types, String, Array and Imports

    這篇文章主要介紹了詳解 Kotlin Reference Basic Types, String, Array and Imports的相關(guān)資料,需要的朋友可以參考下
    2017-06-06
  • Android中協(xié)調(diào)滾動(dòng)布局的實(shí)現(xiàn)代碼

    Android中協(xié)調(diào)滾動(dòng)布局的實(shí)現(xiàn)代碼

    這篇文章主要介紹了Android中協(xié)調(diào)滾動(dòng)常用的布局實(shí)現(xiàn),類似這樣的協(xié)調(diào)滾動(dòng)布局,當(dāng)?shù)撞苛斜砘瑒?dòng)的時(shí)候,頂部的布局做響應(yīng)的動(dòng)作,我們都可以通過(guò)?AppBarLayout?和?MotionLayout?來(lái)實(shí)現(xiàn),本文通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友參考下吧
    2022-06-06
  • Android 廣播監(jiān)聽(tīng)網(wǎng)絡(luò)狀態(tài)詳解及實(shí)例代碼

    Android 廣播監(jiān)聽(tīng)網(wǎng)絡(luò)狀態(tài)詳解及實(shí)例代碼

    這篇文章主要介紹了Android 廣播監(jiān)聽(tīng)網(wǎng)絡(luò)狀態(tài)詳解及實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下
    2017-02-02

最新評(píng)論