Button的使用(六):ToggleButton
根据ToggleButton的选项来设置屏幕的方向
package com.example.androidtest;import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.content.pm.ActivityInfo;
import android.widget.CompoundButton;
import android.widget.ToggleButton;
import android.content.res.Configuration;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.util.Log;public class MainActivity extends Activity {public void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);ToggleButton toggle = (ToggleButton)findViewById(R.id.toggleButton);if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {toggle.setChecked(true);} else {toggle.setChecked(false);}toggle.setOnCheckedChangeListener(listener);}OnCheckedChangeListener listener = new OnCheckedChangeListener(){public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){int current = getResources().getConfiguration().orientation;Log.d("wuli", "current:" + current);if (isChecked) {switch (current) {case Configuration.ORIENTATION_LANDSCAPE:setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);break;case Configuration.ORIENTATION_PORTRAIT:setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);break;default:setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);}} else {setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);}}};}
xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><ToggleButton android:id="@+id/toggleButton"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textOff="Lock"android:textOn="LOCKED"/>
</LinearLayout>
Button的使用(六):ToggleButton相关推荐
- Android ToggleButton:状态切换的Button
Android ToggleButton:状态切换的Button Android ToggleButton和Android Button类似,但是ToggleButton提供了一种选择机制,可以 ...
- 使用Kotlin的Android ToggleButton
In this tutorial, we'll learn how to implement Android ToggleButton using Kotlin. We will learn how ...
- 初学Android,音频管理器之控制音频(六十六)
下面要写的是AudioManager这个音频管理器,它可以通过getSystemService得到 有一个重要方法adjustStreamVolumn(int streamType,int direc ...
- Android Button 属性详解
Button认知 public class Button extends TextView java.lang.Object↳ android.view.View↳ android.widget.Te ...
- android入门基础笔记,Sqlite数据库下载
* 移动通讯技术的发展: 第一代通讯技术:模拟信号 工作频段 缺点:保密性差 第二代通讯技术: 体积越来越小 数字信号(加密) 短信 彩信 第三代通讯技术: 数字信号 可处理图像.音乐 ...
- Android Studio 学习实例记录-手电筒
Android Studio 学习实例记录-手电筒 刚安装好Android Studio3.1.2,上网搜了一个实例进行实践学习,仅用这篇文章来记录学习过程 MainActivity.java的源码来 ...
- 安卓应用开发期末与面试概念冲刺(概念与代码,from hitwh)
安卓应用开发概念冲刺(概念与代码) 前三章 安卓整体体系结构(四个)以及其中包含什么 安卓将()和()分离? intent和Service的用处.ContentProvider用处 安卓四大核心组件 ...
- 微信公众平台开发(58)自定义菜单
微信公众平台开发 微信公众平台开发模式 企业微信公众平台 自定义菜单 开发教程 作者:方倍工作室 地址:http://www.cnblogs.com/txw1958/p/weixin-58-cus ...
- android 变化字体,android 字体修改
android字体的设置有以下方法: 1)直接在代码设置Typeface customFont = Typeface.createFromAsset(this.getAssets(), "1 ...
最新文章
- linux限制显卡频率,关于安装Linux (FC6)频率超出范围与显卡驱动
- 用博奥如何导入单项工程电子表_用博奥如何导入单项工程电子表_博奥常见问题处理汇总...
- 联想拯救者Y7000P 2021H deepin v20.2.4设置双屏显示:切记要用集显,NAVIDA独显不生效
- linux性能并发 带机量,性能测试笔记(一):吞吐量与并发数
- 一次Python性能调优经历
- Maven安装与配制环境【win7/win10】
- 深入剖析 redis AOF 持久化策略
- day31 模块 与包
- 学生宿舍管理项目开发计划书_学生宿舍管理系统项目-计划书.doc
- 2021-11-23日win10更新bug:共享打印机无法连接的修复
- 鸿蒙大陆7.1正式版隐藏英雄,守塔V7.01下载 守塔V7.01正式版 附游戏攻略及隐藏英雄密码 魔兽防守地图 下载-脚本之家...
- Apache下如何安装ssl证书?PHPWAMP如何开启SSL
- CodeSmith连接MySql数据库
- 用Python制作我的核酸检测日历
- 转:隐马尔可夫模型(HMM)攻略
- python PIL库中的getpixel函数
- 计算机视觉常用资源整理
- ASA与FTD的基本配置
- 微信公众号运营商,如何选择适合自己的微信第三方平台?
- Cramer-Rao下界
热门文章
- SQL SERVER 2008 R2 SP1更新时,遇上共享功能更新失败解决方案
- RS-232串行口连接线 com口连接线 并口链接线 双绞线 交叉线 直连线
- 开始喜欢Python了
- 零基础学python爬虫-我是如何零基础开始能写Python爬虫的
- python3.8.2安装教程-在服务器上安装python3.8.2环境的教程详解
- 快速排序 python菜鸟教程-十大编程算法助程序员走上高手之路
- python官方-Python官方中文文档强势来袭
- 简明python教程购买-自学Python买什么书?
- python变量类型-python变量的数据类型有哪些?
- python散点图拟合曲线-python – 将曲线拟合到散点图的边界