Didn‘t find class “android.view.View$OnUnhandledKeyEventListener“,Didn‘t find class “androidx
Android 新導入的項目,報錯:
?java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rikkathewrold.rikkamusic/com.rikkathewrold.rikkamusic.login.mvp.view.SelectLoginActivity}: java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation
或
Only fullscreen activities can request orientation
解決方法
添加屏幕方向和透明度設置
BaseActivity一次性添加。或者在各個activity分別添加
工具方法
private boolean fixOrientation(){
? ? try {
? ? ? ? Field field = Activity.class.getDeclaredField("mActivityInfo");
? ? ? ? field.setAccessible(true);
? ? ? ? ActivityInfo o = (ActivityInfo)field.get(this);
? ? ? ? o.screenOrientation = -1;
? ? ? ? field.setAccessible(false);
? ? ? ? return true;
? ? } catch (Exception e) {
? ? ? ? e.printStackTrace();
? ? }
? ? return false;
}
private boolean isTranslucentOrFloating(){
? ? boolean isTranslucentOrFloating = false;
? ? try {
? ? ? ? int [] styleableRes = (int[]) Class.forName("com.android.internal.R$styleable").getField("Window").get(null);
? ? ? ? final TypedArray ta = obtainStyledAttributes(styleableRes);
? ? ? ? Method m = ActivityInfo.class.getMethod("isTranslucentOrFloating", TypedArray.class);
? ? ? ? m.setAccessible(true);
? ? ? ? isTranslucentOrFloating = (boolean)m.invoke(null, ta);
? ? ? ? m.setAccessible(false);
? ? } catch (Exception e) {
? ? ? ? e.printStackTrace();
? ? }
? ? return isTranslucentOrFloating;
}
在super.onCreate(savedInstanceState);????方法前添加設置方法
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
? ? supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
? ? if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O && isTranslucentOrFloating()) {
? ? ? ? boolean result = fixOrientation();
? ? }
? ? super.onCreate(savedInstanceState);
?
附:
@Override
public void setRequestedOrientation(int requestedOrientation) {
? ? if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O && isTranslucentOrFloating()) {
? ? ? ? return;
? ? }
? ? super.setRequestedOrientation(requestedOrientation);
}
?
Didn't find class "androidx
compile 'com.android.support:support-v4:4.4.1'?
?
總結
以上是生活随笔為你收集整理的Didn‘t find class “android.view.View$OnUnhandledKeyEventListener“,Didn‘t find class “androidx的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: nachos操作系统初步认识
- 下一篇: 关于 HenCoder