Java 如何在android中通过编程禁用软键?
是否有任何方法可以通过编程禁用软键Java 如何在android中通过编程禁用软键?,java,android,android-view,android-homebutton,Java,Android,Android View,Android Homebutton,是否有任何方法可以通过编程禁用软键 public boolean isSoftKeyAvail(Context context) { final boolean[] isSoftkey = {false}; final View activityRootView = ((Activity) context).getWindow().getDecorView().findViewById(android.R.id.content); activityRootView.get
public boolean isSoftKeyAvail(Context context) {
final boolean[] isSoftkey = {false};
final View activityRootView = ((Activity) context).getWindow().getDecorView().findViewById(android.R.id.content);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int rootViewHeight = activityRootView.getRootView().getHeight();
int viewHeight = activityRootView.getHeight();
int heightDiff = rootViewHeight - viewHeight;
if (heightDiff > 100) { // 99% of the time the height diff will be due to a keyboard.
isSoftkey[0] = true;
}
}
});
return isSoftkey[0];
}
public int getStatusBarHeight(){
int result=0;
int resourceId= mContext.getResources().getIdentifier("status_bar_height", "dimen", "android");
if(resourceId >0)
result = mContext.getResources().getDimensionPixelSize(resourceId);
return result;
}
使用以下命令:
@Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
或将清单设置为:
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MONKEY"/>
试试这个
InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
尝试以下操作:@Override public void onAttachedToWindow(){this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_对话框);KeyguardManager KeyguardManager=(KeyguardManager)getSystemService(KEYGUARD_服务);KeyguardLock=KeyguardManager.newKeyguardLock(KEYGUARD_服务);lock.disableKeyguard();}
InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);