星空网 > 软件开发 > 操作系统

android 获得屏幕状态

<RelativeLayout ="http://schemas.android.com/apk/res/android"  ="http://schemas.android.com/tools"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical" >  <!-- 定义获得屏幕状态的按钮 -->  <Button    android:id="@+id/reenableKeyguard"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:text="屏幕的状态" /></RelativeLayout>

package com.example.yanlei.yl;import android.app.KeyguardManager;import android.content.Context;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.Toast;public class MainActivity extends AppCompatActivity {  // 定义锁屏的按钮  private Button btnKeyguard;  //声明KeyguardManager对象  private KeyguardManager keyguardManager;  @Override  public void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main);    // 获得KeyguardManager服务    keyguardManager=(KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);    //得到布局中的所有对象    findView();    //设置对象的**    setListener();  }  private void findView() {    // 得到布局中的所有对象    btnKeyguard = (Button) findViewById(R.id.reenableKeyguard);  }  private void setListener() {    // 设置对象的**    btnKeyguard.setOnClickListener(new OnClickListener() {      @Override      public void onClick(View arg0) {        // TODO Auto-generated method stub        //判断当前屏幕的状态        if(keyguardManager.isKeyguardLocked())        {          Toast.makeText(MainActivity.this, "锁屏", Toast.LENGTH_SHORT).show();        }        else        {          Toast.makeText(MainActivity.this, "没有锁屏", Toast.LENGTH_SHORT).show();        }      }    });  }}

 




原标题:android 获得屏幕状态

关键词:Android

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

“注重用户体验” “优先本地化运营” 聊聊Grab在东南亚的生意经!:https://www.goluckyvip.com/news/4879.html
注意!这些国家海关已与中国联网,大力打击发票低开!:https://www.goluckyvip.com/news/488.html
万事俱备只等旺季,物流踩雷毁所有:https://www.goluckyvip.com/news/4880.html
跨境电商卖家如何借助tiktok找红人?:https://www.goluckyvip.com/news/4881.html
海运挤爆!美西港口全线告急!船公司辟谣停运传言:https://www.goluckyvip.com/news/4882.html
【福利】TikTok注册及安装攻略免费送!:https://www.goluckyvip.com/news/4883.html
美国版权小知识-哪些作品能够登记美国版权?:https://www.kjdsnews.com/a/1836627.html
俄罗斯汽车企业进口东风汽车零部件组装雪铁龙汽车:https://www.kjdsnews.com/a/1836628.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流