Configration--获取屏幕属性


         


<? xml version= "1.0" encoding= "utf-8" ?>

<LinearLayout xmlns: android ="http://schemas.android.com/apk/res/android"

    android :layout_width= "match_parent"

    android :layout_height= "match_parent"

    android :orientation= "vertical"

    >

    <EditText

        android :id= "@+id/ori"

        android :hint= "显示屏幕方向"

        android :layout_width= "match_parent"

        android :layout_height= "wrap_content" />

    <EditText

        android :id= "@+id/navigation"

        android :hint= "显示手机方向控制设备"

        android :layout_width= "match_parent"

        android :layout_height= "wrap_content" />

    <EditText

        android :id= "@+id/touch"

        android :hint= "显示触摸屏状态"

        android :layout_width= "match_parent"

        android :layout_height= "wrap_content" />

    <EditText

        android :id= "@+id/mnc"

        android :hint= "显示移动网络代号"

        android :layout_width= "match_parent"

        android :layout_height= "wrap_content" />

    <Button

        android :id= "@+id/bn"

        android :text= "获取手机信息"

        android :layout_width= "wrap_content"

        android :layout_height= "wrap_content" />

</LinearLayout>



主程序获取手机屏幕的属性

package com.eson.configuration ;




import android.content.res.Configuration ;

import android.os.Bundle ;

import android.support.v7.app.AppCompatActivity ;

import android.view.View ;

import android.widget.Button ;

import android.widget.EditText ;




public class ConfigurationTest extends AppCompatActivity {




    private EditText ori;

    private EditText natigation ;

    private EditText mnc ;

    private Button bn ;

    private EditText touch ;




    @Override

    protected void onCreate (Bundle savedInstanceState) {

        super .onCreate(savedInstanceState) ;

        setContentView(R.layout. content_main );




        //获取应用交界中的界面组件

        ori = (EditText) findViewById(R.id. ori );

        natigation = (EditText) findViewById(R.id. navigation );

        touch = (EditText) findViewById(R.id. touch );

        mnc = (EditText) findViewById(R.id. mnc );

        bn = (Button) findViewById(R.id. bn );

        bn .setOnClickListener( new View.OnClickListener() {

            //为按钮绑定事件监听器

            @Override

            public void onClick (View v) {

                //获取系统的Configuration对象

                Configuration cfg=getResources().getConfiguration() ;

                String screen=cfg.orientation ==Configuration. ORIENTATION_LANDSCAPE ?"横向屏幕" : "竖向屏幕" ;

                String mncCode=cfg.mnc + "";

                String natiName=cfg.orientation ==Configuration. NAVIGATION_NONAV

                        ? "没有方向控制" :cfg.orientation ==Configuration. NAVIGATION_WHEEL

                        ? "滚轮控制方向" :cfg.orientation ==Configuration. NAVIGATION_DPAD

                        ? "方向键盘控制方向" : "轨迹球控制方向" ;

                natigation.setText(natiName) ;

                String touchName=cfg.touchscreen ==Configuration. TOUCHSCREEN_NOTOUCH

                        ? "无触摸屏" :"支持触摸屏" ;

                ori.setText(screen) ;

                mnc.setText(mncCode) ;

                touch.setText(touchName) ;

            }

        });

    }

}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值