禁用HOME键和返回键"HOME、QUOT

2023-09-07 13:48:50 作者:7.笑眼迷人

我想办法禁用home键和放大器;后退按钮时,点击应用程序复选框,

i want way to disable the Home Button & Back Button when click on checkbox in application ,

我在4.2.2版本的应用程序

my application on version 4.2.2

我有code,但不工作的时候点击复选框工作停止的应用程序

i have code but not work when click on checkbox work stop to application

public void HardButtonOnClick(View v)
    {
            boolean checked1 = ((CheckBox) v).isChecked();
            if(checked1)
            {   
                SQLiteDatabase db;                      
                db = openOrCreateDatabase("Saftey.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
                db.setVersion(1);
                db.setLocale(Locale.getDefault());
                db.setLockingEnabled(true);
                ContentValues values = new ContentValues();
                values.put("hardBtn", "YES");
                db.update("Setting", values, "id = ?", new String[] { "1" });
                Toast.makeText(this, "Hard Button Locked", Toast.LENGTH_LONG).show();
                //SharedPreferences pref = getSharedPreferences("pref",0);
                //SharedPreferences.Editor edit = pref.edit();
                //edit.putString("hard","yes");
                //edit.commit();
                /* String Lock="yes" ;
                 Bundle bundle = new Bundle();
                 bundle.putString("key", Lock);
                 Intent a = new Intent(Change_setting.this, ChildMode.class);
                 a.putExtras(bundle);
                 startActivity(a);*/
                super.onAttachedToWindow();
                this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
                isLock = true;
            }
            else
            {
                SQLiteDatabase db;                      
                db = openOrCreateDatabase("Saftey.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
                db.setVersion(1);
                db.setLocale(Locale.getDefault());
                db.setLockingEnabled(true);
                ContentValues values = new ContentValues();
                values.put("hardBtn", "NO");
                db.update("Setting", values, "id = ?", new String[] { "1" });
                //SharedPreferences pref = getSharedPreferences("pref",0);
                //SharedPreferences.Editor edit = pref.edit();
                //edit.putString("hard","no");
                //edit.commit();
                Toast.makeText(this, "Hard Button Un-Locked", Toast.LENGTH_LONG).show();
                isLock = false;
            }
    }

如何解决它?

我不想隐瞒点击,但只有当点击home键不起作用任何事情

I do not want to hide clickable but only when click on home button does not work any thing

推荐答案

您可以覆盖返回键 onBack pressed(),让它做什么,但你不能覆盖的home键,但你可以添加一些code到的onStop()这是在home键preSS调用。

You can override the back key onBackPressed() and let it do nothing, but you can't override the home button but you can add some code to onStop() which is called upon home key press.

下面是一片code来控制回preSS

here is a piece of code to control backpress

@Override
public void onBackPressed()
{
    if ( checked1 ) // if checked do nothing , remeber tomove checked1 to be a class member
        return;
    super.onBackPressed();
}
 
精彩推荐