2017-09-27 1 views
1

Android Soft Keyboard에서 작업 중이며 키에 대한 사용자 정의 테마를 적용 중입니다.레이아웃을 부 풀릴 때 java.lang.ClassCastException이 발생했습니다.

@Override 
public View onCreateInputView() { 

    // Set custom theme to input view. 
    int themeLayout = sharedPreferences.getInt(THEME_KEY, R.layout.input_1); 
    mInputView = (LatinKeyboardView) getLayoutInflater().inflate(
      themeLayout, null); 
    mInputView.setOnKeyboardActionListener(this); 

    // Apply the selected keyboard to the input view. 
    setLatinKeyboard(getSelectedSubtype()); 

    return mInputView; 
} 

그러나 나는 다음과 같은 오류가 점점 오전 :

나는 다음 코드를 사용하여이 일을하고

java.lang.ClassCastException: at com.xxx.xxx.android.SoftKeyboard.onCreateInputView (SoftKeyboard.java:159) at com.xxx.xxx.android.SoftKeyboard.onStartInput (SoftKeyboard.java:232) at android.inputmethodservice.InputMethodService.doStartInput (InputMethodService.java:2641) at android.inputmethodservice.InputMethodService$InputMethodImpl.startInput (InputMethodService.java:590) at android.inputmethodservice.IInputMethodWrapper.executeMessage (IInputMethodWrapper.java:186) at com.android.internal.os.HandlerCaller$MyHandler.handleMessage (HandlerCaller.java:37) at android.os.Handler.dispatchMessage (Handler.java:102) at android.os.Looper.loop (Looper.java:154) at android.app.ActivityThread.main (ActivityThread.java:6682) at java.lang.reflect.Method.invoke (Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1520) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1410)

레이아웃 :

<com.sunzala.xxxx.android.LatinKeyboardView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/keyboard" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:background="@drawable/kb_bg_1" 
    android:keyBackground="@drawable/key_bg_fill_grey" 
    android:keyPreviewLayout="@layout/key_preview_layout" 
    android:keyPreviewOffset="@dimen/keyPreviewOffset" 
    android:keyTextColor="@color/white" 
    android:popupLayout="@layout/keyboard_popup_layout" /> 

이 내가에 테스트입니다 때 작동 내 장치가 있지만 응용 프로그램을 게시 한 후 오류 로그에 오류가 발생했습니다.

답변

1

아마도 프로 가드가 사용자 정의보기를 축소했습니다. build.gradle 파일의 릴리스 블록에서 minifyEnabled를 false로 설정하여 proguard를 비활성화 할 수 있습니다.

proguard를 사용하려면 proguard-rules.pro에 다음 행을 추가하여 사용자 정의보기를 유지하십시오.

-keep public class * extends android.view.View { 
    public <init> (android.content.Context); 
    public <init> (android.content.Context , android.util.AttributeSet); 
    public <init> (android.content.Context , android.util.AttributeSet , int); 
    public void set *(...); 
} 
+0

축소 된 proguard는 gradle에서는 사용할 수 없습니다. –

관련 문제