分享

安卓锁屏的实现

 quasiceo 2017-10-19

2013-12-29 14:24 722人阅读 评论(1) 收藏 举报
分类:
  1. <pre code_snippet_id="133065" snippet_file_name="blog_20131229_1_4486551" name="code" class="html">MainActivity.java</pre>  
  2. <pre></pre>  
  3. <pre code_snippet_id="133065" snippet_file_name="blog_20131229_2_8914416" name="code" class="html">package com.example.lockscreen;  
  4.   
  5. import android.os.Bundle;  
  6. import android.app.Activity;  
  7. import android.content.Intent;  
  8. import android.view.Menu;  
  9. import android.view.View;  
  10. import android.view.View.OnClickListener;  
  11. import android.widget.Button;  
  12.   
  13. public class MainActivity extends Activity {  
  14.       
  15.     private Button startBt ;  
  16.     private Button stopBt;  
  17.       
  18.     @Override  
  19.     protected void onCreate(Bundle savedInstanceState) {  
  20.         super.onCreate(savedInstanceState);  
  21.         initView();  
  22.     }  
  23.   
  24.     private void initView() {  
  25.         setContentView(R.layout.activity_main);  
  26.         this.startBt = (Button)super.findViewById(R.id.startBt);  
  27.         this.stopBt  = (Button)super.findViewById(R.id.closeBt);  
  28.         this.startBt.setOnClickListener(onClickListener);  
  29.         this.stopBt.setOnClickListener(onClickListener);  
  30.           
  31.           
  32.     }  
  33.       
  34.       
  35.       
  36.     @Override  
  37.     public boolean onCreateOptionsMenu(Menu menu) {  
  38.         // Inflate the menu; this adds items to the action bar if it is present.  
  39.         getMenuInflater().inflate(R.menu.main, menu);  
  40.         return true;  
  41.     }  
  42.       
  43.   
  44.     private void startservice(){  
  45.         Intent intent = new Intent();  
  46.         intent.setClass(this, ScreenService.class);  
  47.         this.startService(intent);  
  48.           
  49.     }  
  50.       
  51.       
  52.     private void stopService(){  
  53.         Intent intent = new Intent();  
  54.         intent.setClass(this, ScreenService.class);  
  55.         this.stopService(intent);  
  56.     }  
  57.       
  58.     private OnClickListener onClickListener = new OnClickListener() {  
  59.           
  60.         @Override  
  61.         public void onClick(View v) {  
  62.         switch (v.getId()) {  
  63.         case R.id.startBt:  
  64.             startservice();  
  65.             break;  
  66.   
  67.         case R.id.closeBt:  
  68.               
  69.             stopService();  
  70.             break;  
  71.         }  
  72.               
  73.         }  
  74.     };  
  75.       
  76.       
  77.       
  78.       
  79.   
  80. }  
  81. </pre><pre code_snippet_id="133065" snippet_file_name="blog_20131229_3_3723966" name="code" class="html">package com.example.lockscreen;  
  82.   
  83. import android.app.Activity;  
  84. import android.os.Bundle;  
  85.   
  86. public class ScreenOnActivity extends Activity {  
  87.   
  88.       
  89.     @Override  
  90.     protected void onCreate(Bundle savedInstanceState) {  
  91.         // TODO Auto-generated method stub  
  92.         super.onCreate(savedInstanceState);  
  93.         super.setContentView(R.layout.screenon);  
  94.     }  
  95. }  
  96. </pre><br>  
  97. <br>  
  98.      
0
0
查看评论
1楼 蜗牛也上树 2014-12-02 14:54发表 [回复]
没写完吧啊,代码都跑不起来

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约