RabNawaz Chaudhary
RabNawaz Chaudhary

Reputation: 1

How to change themes in custom keyboard in android

@Override public View onCreateInputView() {

    //Start SharedPreferences Fetch
    SharedPreferences pref1=getSharedPreferences("test",1);
    int theme=pref1.getInt("theme1",1);

    int theme_1=pref1.getInt("theme2",2);

    if(theme==1)
    {
        this.mInputView= (LatinKeyboardView) this.getLayoutInflater().inflate(R.layout.input2,null);
    }
     else if(theme_1==1)
    {
        this.mInputView= (LatinKeyboardView) this.getLayoutInflater().inflate(R.layout.input,null);
    }
    //End SharedPreferences Fetch

// mInputView = (LatinKeyboardView) getLayoutInflater().inflate( // R.layout.input, null);

    this.mInputView.setOnKeyboardActionListener(this);
//    mInputView.setPreviewEnabled(false);
   this.mInputView.setKeyboard(mQwertyKeyboard);
    return this.mInputView;
}

Upvotes: 0

Views: 678

Answers (1)

cwbowron
cwbowron

Reputation: 1025

I'm not exactly sure what you are trying to do, but ContextThemeWrapper might be what you are looking for. Instead of inflating based on the current context, you can create a ContextThemeWrapper, and use that to inflate your XML.

Context themedContext = new ContextThemeWrapper(context,themeId);
LayoutInflator.from(themedContext).inflate(...)

Upvotes: 1

Related Questions