第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

關(guān)于ToggleButton的內(nèi)容,出現(xiàn)的問題是在imageView的初始化圖片,一直存在無法被覆蓋

package?com.example.willow.myapplication5;

import?android.support.v7.app.AppCompatActivity;
import?android.os.Bundle;
import?android.widget.CompoundButton;
import?android.widget.ImageView;
import?android.widget.ToggleButton;


public?class?MainActivity5?extends?AppCompatActivity?implements?CompoundButton.OnCheckedChangeListener?{
????//設(shè)置控件對象對相關(guān)的控件進行操作
????private?ToggleButton?tb;
????private?ImageView?img;

????@Override
????protected?void?onCreate(Bundle?savedInstanceState)?{
????????super.onCreate(savedInstanceState);
????????setContentView(R.layout.activity_main5);

????????//初始化控件
????????tb?=?(ToggleButton)?findViewById(R.id.toggleButton);
????????img?=?(ImageView)findViewById(R.id.imageView);

????????/**
?????????*?給當(dāng)前的tb按鈕設(shè)置監(jiān)聽事件(監(jiān)聽器)
?????????*/
????????tb.setOnCheckedChangeListener(this);


????}
????//重寫方法onCheckedChanged()
????public?void?onCheckedChanged(CompoundButton?buttonView,boolean?isChecked){
????????/**
?????????*?當(dāng)tb被點擊的時候,當(dāng)前的方法會執(zhí)行
?????????*
?????????*?buttonView----代表被點擊控件的本身
?????????*?isChecked---代表被點擊的控件的狀態(tài)
?????????*
?????????*?當(dāng)點擊這個tb的時候,更換img的背景
?????????*
?????????*/
????????img.setBackgroundResource(isChecked?R.drawable.on:R.drawable.off);
????}

//????@Override
//????public?void?onPointerCaptureChanged(boolean?hasCapture)?{
//????????/**
//?????????*?當(dāng)tb被點擊的時候,當(dāng)前的方法會執(zhí)行
//?????????*
//?????????*?buttonView----代表被點擊控件的本身
//?????????*?isChecked---代表被點擊的控件的狀態(tài)
//?????????*
//?????????*?當(dāng)點擊這個tb的時候,更換img的背景
//?????????*
//?????????*/
//????????img.setBackgroundResource(hasCapture?R.drawable.on:R.drawable.off);
//????}

//????@Override
//????public?void?onCheckedChanged(CompoundButton?buttonView,?boolean?isChecked)?{
//
//????}
}
<?xml?version="1.0"?encoding="utf-8"?>
<android.support.constraint.ConstraintLayout?xmlns:android="http://schemas.android.com/apk/res/android"
????xmlns:app="http://schemas.android.com/apk/res-auto"
????xmlns:tools="http://schemas.android.com/tools"
????android:layout_width="match_parent"
????android:layout_height="match_parent"
????tools:context=".MainActivity5">

????<!--textOff?fluse狀態(tài)?textOn?ture狀態(tài)??-->
????<ToggleButton
????????android:id="@+id/toggleButton"
????????android:checked="false"
????????android:textOff="@string/Off"
????????android:textOn="@string/turn"
????????android:layout_width="match_parent"
????????android:layout_height="wrap_content"
????????tools:layout_editor_absoluteX="72dp"
????????tools:layout_editor_absoluteY="16dp"?/>

????<!--android:src="@drawable/baign"-->
????<ImageView
????????android:id="@+id/imageView"
????????android:layout_width="match_parent"
????????android:layout_height="match_parent"
????????tools:layout_editor_absoluteX="136dp"
????????tools:layout_editor_absoluteY="228dp"?/>
</android.support.constraint.ConstraintLayout>
<resources>
????<string?name="app_name">ToggleButton</string>
????<string?name="turn">開</string>
????<string?name="Off">關(guān)</string>
</resources>


正在回答

1 回答

//先執(zhí)行一次image處理,顯示關(guān)的狀態(tài)
img.setBackgroundResource(R.drawable.off);


0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消
Android攻城獅的第一門課(入門篇)
  • 參與學(xué)習(xí)       312508    人
  • 解答問題       4931    個

想快速掌握Android應(yīng)用開發(fā)基礎(chǔ),選擇學(xué)習(xí)這門課程就對了。

進入課程

關(guān)于ToggleButton的內(nèi)容,出現(xiàn)的問題是在imageView的初始化圖片,一直存在無法被覆蓋

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號