成人无码视频,亚洲精品久久久久av无码,午夜精品久久久久久毛片,亚洲 中文字幕 日韩 无码

資訊專欄INFORMATION COLUMN

如何利用ToggleButton切換圖片

weizx / 3121人閱讀

摘要:如何利用切換圖片文件給當前的設置監(jiān)聽器實現(xiàn)接口來設置監(jiān)聽,當點擊按鈕的時候開始執(zhí)行方法代表被點擊的控件按鈕被點擊控件的狀態(tài)當點擊開關的時候,更換的背景布局文件關開效果圖

如何利用ToggleButton切換圖片
java文件

    package com.example.administrator.app;
    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.CompoundButton;
    import android.widget.ImageView;
    import android.widget.ToggleButton;
    public class toggleBtn extends Activity implements    CompoundButton.OnCheckedChangeListener {
    private ToggleButton tb;
    private ImageView img;
    protected void onCreate(Bundle saveInstanceState){
    super.onCreate(saveInstanceState);
    setContentView(R.layout.togglebutton);
    tb = (ToggleButton)findViewById(R.id.toggle_button);
    img = (ImageView) findViewById(R.id.imageView);
    /**

給當前的tb設置監(jiān)聽器
*/
tb.setOnCheckedChangeListener(this);

}

 //Called when the checked state of a compound button has changed.
 //@param buttonView The compound button view whose state has changed.
 //@param isChecked  The new checked state of buttonView.

@Override

void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

   
     //實現(xiàn)接口CompoundButton.OnCheckedChangeListener 來設置tb監(jiān)聽,當點擊  按鈕tb的時候開始執(zhí)行
    // onCheckedChanged方法
    //buttonView 代表被點擊的控件按鈕
    // isChecked  被點擊控件的狀態(tài)
    //當點擊tb開關的時候,更換img的背景
   img.setBackgroundResource(isChecked?R.drawable.on:R.drawable.off);
}

}
布局文件

android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

效果圖:


文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉載請注明本文地址:http://m.hztianpu.com/yun/64729.html

相關文章

  • React 組件之間如何交流

    摘要:前言今天群里面有很多都在問關于組件之間是如何通信的問題,之前自己寫的時候也遇到過這類問題。英文能力有限,如果有不對的地方請跟我留言,一定修改原著序處理組件之間的交流方式,主要取決于組件之間的關系,然而這些關系的約定人就是你。 前言 今天群里面有很多都在問關于 React 組件之間是如何通信的問題,之前自己寫的時候也遇到過這類問題。下面是我看到的一篇不錯英文版的翻譯,看過我博客的人都知道...

    tomlingtm 評論0 收藏0
  • pyqt5——控件1

    摘要:有很多的控件,比如按鈕,單選框,滑動條,復選框等等。要設置窗口標題,我們就要檢查單選框的狀態(tài)。我們創(chuàng)建了一個水平的進度條和一個按鈕,這個按鈕控制進度條的開始和停止。這個例子有日期組件和標簽組件組成,標簽顯示被選中的日期。 控件1 控件就像是應用這座房子的一塊塊磚。PyQt5有很多的控件,比如按鈕,單選框,滑動條,復選框等等。在本章,我們將介紹一些很有用的控件:QCheckBox,Tog...

    fnngj 評論0 收藏0

發(fā)表評論

0條評論

weizx

|高級講師

TA的文章

閱讀更多
最新活動
閱讀需要支付1元查看
<