你好的人在StackOverflow上,應用主題動態的Android鍵盤
我遇到了一個問題,同時編程軟鍵盤:
我想要實現的是軟鍵盤動態加載一個主題/風格的優化在夜間打字和在陽光下打字的主題/風格。這些樣式已經定義好了,我可以通過改變input.xml中的樣式來輕鬆切換它們。
import ... /*Not quite relevant (yet)*/
public class LatinKeyboardView extends KeyboardView {
public LatinKeyboardView(Context context, AttributeSet attrs) {
this(context, attrs, loadColor());
}
public LatinKeyboardView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public static int loadColor() {
String dbg = android.os.Debug.isDebuggerConnected() ? "Y" : "N";
android.util.Log.d("loadColor", "Debugger connected: " + dbg);
android.os.Debug.waitForDebugger();
int temp = 0;
int id = 0;
if (temp == 1)
{
id = R.style.KeyStyle_Day;
}
else
{
id = R.style.KeyStyle_Night;
}
android.util.Log.d("loadColor", Integer.toString(id));
return id;
}
當我重定向從第一構造到第二構造(如被看見在黑客的鍵盤源代碼)的呼叫時,軟鍵盤中成功加載loadColor()的風格ID,但之後呢,有內部發生一個例外,我無法追溯,即使堆棧跟蹤:
03-19 08:32:48.313 18630-18630/com.alphanerd.eztype.keyboard E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.alphanerd.eztype.keyboard, PID: 18630
android.view.InflateException: Binary XML file line #21: Error inflating class com.alphanerd.eztype.keyboard.LatinKeyboardView
at android.view.LayoutInflater.createView(LayoutInflater.java:626)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
at android.view.LayoutInflater.inflate(LayoutInflater.java:470)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at com.alphanerd.eztype.keyboard.EZTypeKeyboard.onCreateInputView(EZTypeKeyboard.java:125)
at android.inputmethodservice.InputMethodService.updateInputViewShown(InputMethodService.java:1594)
at android.inputmethodservice.InputMethodService.showWindowInner(InputMethodService.java:2220)
at android.inputmethodservice.InputMethodService.showWindow(InputMethodService.java:2179)
at android.inputmethodservice.InputMethodService$InputMethodImpl.showSoftInput(InputMethodService.java:712)
at android.inputmethodservice.IInputMethodWrapper.executeMessage(IInputMethodWrapper.java:214)
at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:40)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:600)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
at android.view.LayoutInflater.inflate(LayoutInflater.java:470)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at com.alphanerd.eztype.keyboard.EZTypeKeyboard.onCreateInputView(EZTypeKeyboard.java:125)
at android.inputmethodservice.InputMethodService.updateInputViewShown(InputMethodService.java:1594)
at android.inputmethodservice.InputMethodService.showWindowInner(InputMethodService.java:2220)
at android.inputmethodservice.InputMethodService.showWindow(InputMethodService.java:2179)
at android.inputmethodservice.InputMethodService$InputMethodImpl.showSoftInput(InputMethodService.java:712)
at android.inputmethodservice.IInputMethodWrapper.executeMessage(IInputMethodWrapper.java:214)
at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:40)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.inputmethodservice.KeyboardView.<init>(KeyboardView.java:370)
at com.alphanerd.eztype.keyboard.LatinKeyboardView.<init>(LatinKeyboardView.java:53)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:600)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
at android.view.LayoutInflater.inflate(LayoutInflater.java:470)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at com.alphanerd.eztype.keyboard.EZTypeKeyboard.onCreateInputView(EZTypeKeyboard.java:125)
at android.inputmethodservice.InputMethodService.updateInputViewShown(InputMethodService.java:1594)
at android.inputmethodservice.InputMethodService.showWindowInner(InputMethodService.java:2220)
at android.inputmethodservice.InputMethodService.showWindow(InputMethodService.java:2179)
at android.inputmethodservice.InputMethodService$InputMethodImpl.showSoftInput(InputMethodService.java:712)
at android.inputmethodservice.IInputMethodWrapper.executeMessage(IInputMethodWrapper.java:214)
at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:40)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
我希望,你可以幫助我。動態加載顏色的代碼當前與int temp一樣動態; ,但後來我將實現邏輯從sharedpreferences(包括與其他應用我公司正在開發的鍵盤實際上意味着集成(光學))預先加載的顏色任何幫助:)