gpt4 book ai didi

android - 检测菜单按钮事件

转载 作者:行者123 更新时间:2023-11-29 14:52:17 25 4
gpt4 key购买 nike

我想禁用菜单按钮。看了很多文章都没用。
我什至无法检测到菜单按钮按下事件。重写方法,例如onKeyDown()、onKeyUp()、onPrepareOptionsMenu()、onCreateOptionsMenu() 没有工作了。我真的很绝望,请帮忙。

public class MainActivity extends Activity{
TranslateAnimation animateTopLayer;
Button btnOk;
ImageView ivLockMechanism;
ViewGroup rlTopLayer;
FramesSequenceAnimation anim;

@Override
public void onAttachedToWindow() {
getWindow().addFlags(WindowManager.LayoutParams. FLAG_DISMISS_KEYGUARD);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent lockServiceIntent = new Intent(getApplicationContext(),LockService.class);
startService(lockServiceIntent);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.test);
rlTopLayer = (ViewGroup) findViewById(R.id.rlTopLayer);
ivLockMechanism = (ImageView) findViewById(R.id.ivLockMechanism);
btnOk = (Button) findViewById(R.id.btnOk);
btnOk.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
rlTopLayer.startAnimation(animateTopLayer);
}
});
Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.pg_0);
ivLockMechanism.setImageBitmap(b);
anim = AnimationsContainer.getInstance().unlockMechanismAnimation(ivLockMechanism);
animateTopLayer = new TranslateAnimation(0, 500,0, 0);
animateTopLayer.setDuration(1000);
animateTopLayer.setFillAfter(true);
animateTopLayer.setAnimationListener(new AnimationListener() {

@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub

}

@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub

}

@Override
public void onAnimationEnd(Animation animation) {
anim.start();
}
});
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ( Integer.valueOf(android.os.Build.VERSION.SDK) < 7
&& keyCode == KeyEvent.KEYCODE_BACK
&& event.getRepeatCount() == 0) {
onBackPressed();
}

if (keyCode == KeyEvent.KEYCODE_MENU){
return false;
}

return super.onKeyDown(keyCode, event);
}

@Override
public void onBackPressed() {
return;
}

@Override
protected void onPause() {
super.onPause();
finish();
}

最佳答案

这对我有用:

public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU) {
return true;
}
return super.onKeyDown(keyCode, event);
}

Return true to prevent this event from being propagated further, or false to indicate that you have not handled this event and it should continue to be propagated.

@Override
public boolean onPrepareOptionsMenu (Menu menu) {
return false;
}

关于android - 检测菜单按钮事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14501728/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com