WEB开发网
开发学院手机开发Android 开发 Android 屏蔽HOME键 阅读

Android 屏蔽HOME键

 2012-07-04 08:14:48 来源:WEB开发网   
核心提示: package shoujizhengren.co.cc;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.KeyEvent;import android.vie

 package shoujizhengren.co.cc;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.WindowManager;
import android.widget.Toast;
public class Suiping extends Activity {
@Override
protected void onCreate(
Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
@Override
public boolean onKeyDown(
int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
Intent i = new Intent(
Intent.ACTION_MAIN);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addCategory(Intent.CATEGORY_HOME);
startActivity(i);
return true;
}
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
Toast.makeText(
Suiping.this,
"弹出对话框", 1000)
.show();
Intent intent = new Intent(
Suiping.this,
ShoujizhengrenActivity.class);
startActivity(intent);
finish();
return true;
}
else {
return super.onKeyDown(
keyCode, event);
}
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
}

//屏蔽HOME键
public void onAttachedToWindow() {
this.getWindow()
.setType(
WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
super.onAttachedToWindow();
}
}

Tags:Android 屏蔽 HOME

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接