Configuration类响应系统设置的事件处置
2016-08-15 22:50
375 查看
代码:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=" 欢迎光临手机之家 "
android:textColor="#00f"
android:textSize="15pt" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="显示屏幕方向"
android:id="@+id/ori"
android:layout_above="@+id/navigation"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="显示手机方向控制设备"
android:id="@+id/navigation"
android:layout_above="@+id/touch"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="显示触摸屏状态"
android:id="@+id/touch"
android:layout_above="@+id/mnc"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="显示移动网络代号"
android:id="@+id/mnc"
android:layout_above="@+id/bn"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="点击获取手机信息"
android:id="@+id/bn"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
MainActivity.java
<span style="font-size:18px;">package com.example.haige.configuration;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity
{
EditText ori;
EditText navigation;
EditText touch;
EditText mnc;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//获取应用界面中的界面组件
ori=(EditText)findViewById(R.id.ori);
navigation=(EditText)findViewById(R.id.navigation);
touch=(EditText)findViewById(R.id.touch);
mnc=(EditText)findViewById(R.id.mnc);
Button bn=(Button)findViewById(R.id.bn);
bn.setOnClickListener(new View.OnClickListener() {
//为按钮绑定事件监听器
public void onClick(View source)
{
//获取系统的Configuration对象
Configuration cfg=getResources().getConfiguration();
String screen=cfg.orientation ==Configuration.ORIENTATION_LANDSCAPE?"横向屏幕":"竖向屏幕";
String mncCode=cfg.mnc+"";
String naviName=cfg.orientation==Configuration.NAVIGATION_NONAV?"没有方向控制":cfg.orientation==Configuration.NAVIGATION_WHEEL?"滚轮控制方向":cfg.orientation==Configuration.NAVIGATION_DPAD?"方向键控制方向":"轨迹球控制方向";
navigation.setText(naviName);
String touchName=cfg.touchscreen==Configuration.TOUCHSCREEN_NOTOUCH?"无触摸屏":"支持触摸屏";
ori.setText(screen);
mnc.setText(mncCode);
touch.setText(touchName);
}
});
}
}
</span>
运行截图:
总结:
能自动获取Android上一些基本配置的类,感觉挺不错的。
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=" 欢迎光临手机之家 "
android:textColor="#00f"
android:textSize="15pt" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="显示屏幕方向"
android:id="@+id/ori"
android:layout_above="@+id/navigation"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="显示手机方向控制设备"
android:id="@+id/navigation"
android:layout_above="@+id/touch"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="显示触摸屏状态"
android:id="@+id/touch"
android:layout_above="@+id/mnc"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="显示移动网络代号"
android:id="@+id/mnc"
android:layout_above="@+id/bn"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="点击获取手机信息"
android:id="@+id/bn"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
MainActivity.java
<span style="font-size:18px;">package com.example.haige.configuration;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity
{
EditText ori;
EditText navigation;
EditText touch;
EditText mnc;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//获取应用界面中的界面组件
ori=(EditText)findViewById(R.id.ori);
navigation=(EditText)findViewById(R.id.navigation);
touch=(EditText)findViewById(R.id.touch);
mnc=(EditText)findViewById(R.id.mnc);
Button bn=(Button)findViewById(R.id.bn);
bn.setOnClickListener(new View.OnClickListener() {
//为按钮绑定事件监听器
public void onClick(View source)
{
//获取系统的Configuration对象
Configuration cfg=getResources().getConfiguration();
String screen=cfg.orientation ==Configuration.ORIENTATION_LANDSCAPE?"横向屏幕":"竖向屏幕";
String mncCode=cfg.mnc+"";
String naviName=cfg.orientation==Configuration.NAVIGATION_NONAV?"没有方向控制":cfg.orientation==Configuration.NAVIGATION_WHEEL?"滚轮控制方向":cfg.orientation==Configuration.NAVIGATION_DPAD?"方向键控制方向":"轨迹球控制方向";
navigation.setText(naviName);
String touchName=cfg.touchscreen==Configuration.TOUCHSCREEN_NOTOUCH?"无触摸屏":"支持触摸屏";
ori.setText(screen);
mnc.setText(mncCode);
touch.setText(touchName);
}
});
}
}
</span>
运行截图:
总结:
能自动获取Android上一些基本配置的类,感觉挺不错的。
相关文章推荐
- Configuration类响应的系统设置的事件
- 响应的系统设置的事件——Configuration类简介
- Android基础入门教程——3.6 响应系统设置的事件(Configuration类)
- 事件处理机制之响应系统设置的事件(Configuration类)
- 3.6 响应系统设置的事件(Configuration类)
- android之响应的系统设置的事件
- Android事件处理之三 响应的系统设置的事件
- 响应的系统设置的事件
- SYD8801代码解析二【复位等特殊系统行为要等待硬件响应】【协议栈上报事件处理】【时钟源准确度的优化】【修改蓝牙名称】【设置中断优先级】
- android之响应的系统设置的事件
- Android 事件处理详解(三) —— 响应系统设置的事件[Configuration]
- Java 设置窗口系统关闭按钮的事件响应
- Android讲义3---第三章---响应系统设置的事件
- Android之响应的系统设置的事件
- Android学习笔记(六)响应系统设置事件
- 响应的系统设置的事件——重写onConfigurationChanged响应系统设置更改
- 响应的系统设置事件
- c++中设置静态文本框响应点击事件
- 事件处理011(系统设置更改)
- Android 如何才能捕获系统的恢复出厂设置事件