安卓基本控件之ToggleButton
来源:互联网 发布:postman ubuntu 编辑:程序博客网 时间:2024/06/05 00:51
布局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!--ToggleButton 开关 4.0之前使用 -->
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="开"
android:textOff="关"
android:checked="true"
android:onClick="onToggleButton"
/>
<ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bg1"
android:layout_centerInParent="true"
/>
</RelativeLayout>
Java代码
package com.qianfeng.day03_tagglebutton;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;
import android.widget.ToggleButton;
public class MainActivity extends Activity {
private ImageView iv ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (ImageView) findViewById(R.id.iv);
}
public void onToggleButton(View v){
ToggleButton tb = (ToggleButton) v;
boolean isChecked = tb.isChecked();
if(isChecked){
iv.setImageResource(R.drawable.bg1);
}else{
iv.setImageResource(R.drawable.bg);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
- 安卓基本控件之ToggleButton
- 安卓控件——ToggleButton & Switch
- android控件之ToggleButton
- Android控件之ToggleButton
- Android控件之ToggleButton
- 控件记录之toggleButton
- Android控件之ToggleButton
- 安卓基本控件之Button
- 安卓基本控件之CheckBox
- 安卓基本控件之EditText
- 安卓基本控件之ImageButton
- 安卓基本控件之ImageView
- 安卓基本控件之ProgressBar
- 安卓基本控件之RadioButton
- 安卓基本控件之Switch
- 安卓基本控件之TextView
- 安卓基本控件
- Android 控件开发之ToggleButton
- 安装NAGIOS
- python 爬虫4 一些编程注意项目
- 技巧:Linux 动态库与静态库制作及使用详解
- iBarn基于PHP MYSQL开源网盘 - 堪比百度网盘
- 网络问题简单排查
- 安卓基本控件之ToggleButton
- iOS开发之 UIAlertView 沙盒 归档
- 移动应用开发之相关需求文档详细说明
- BigTable
- 小白书之回溯法求素数环
- NFS挂载
- 【cocos2d-x官方文档】怎么使用pthread
- 数据挖掘常见面试题
- Linux下进程管理