3

背景テーマまたはキーボードの色を設定または変更する必要があるカスタムキーボードアプリに取り組んでいます。ユーザーがキー行に異なる背景テーマと異なる色を選択できるアプリのsetting.xmlビュー。アプリケーションの初回起動時は正常に動作していますが、次回カスタム キーボードが表示されたときにテーマが変更されません。

私はこのコードを使用しています:

public class SoftKeyboard extends InputMethodService 
    implements KeyboardView.OnKeyboardActionListener {
static final boolean DEBUG = false;

/**
 * This boolean indicates the optional example code for performing
 * processing of hard keys in addition to regular text generation
 * from on-screen interaction.  It would be used for input methods that
 * perform language translations (such as converting text entered on 
 * a QWERTY keyboard to Chinese), but may not be used for input methods
 * that are primarily intended to be used for on-screen text entry.
 */
static final boolean PROCESS_HARD_KEYS = true;

private static final int SELECT_PICTURE = 101;

private KeyboardView mInputView;
private CandidateView mCandidateView;
private CompletionInfo[] mCompletions;
private Context context = SoftKeyboard.this;
private StringBuilder mComposing = new StringBuilder();
private boolean mPredictionOn;
private boolean mCompletionOn;
private int mLastDisplayWidth;
private boolean mCapsLock;
private long mLastShiftTime;
private long mMetaState;

private LatinKeyboard mSymbolsKeyboard;
private LatinKeyboard mSymbolsShiftedKeyboard;
private LatinKeyboard mQwertyKeyboard;
private LatinKeyboard mSmilyKeyboard;
private LatinKeyboard mSmilyKeyboard1;

private LatinKeyboard mCurKeyboard;

private String mWordSeparators;

/**
 * Main initialization of the input method component.  Be sure to call
 * to super class.
 */

@Override 
   public void onCreate() {
    super.onCreate();

    mWordSeparators = getResources().getString(R.string.word_separators);      
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    String name = preferences.getString("Name","");


    Log.e("SoftKeyboard - ",""+name+"OnCreate Method Called--");



    if(!name.equalsIgnoreCase(""))
    {
      name = name+"  Sethi";  /* Edit the value here*/
    }
}

そして、これは私の設定クラスで、色やテーマを設定または選択しています:

public class Setting extends Activity implements OnClickListener {

    LinearLayout roar, edge, burst, impact, blue_theme, orange_theme,
            green_theme, black_brigthness, white_brightness;

    Bundle bundle;

    public static boolean isblackBrightness = false;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.setting);

        // ----------UI intilisation---------------------
        uiInitilisation();

    }

    public void uiInitilisation() {

        roar = (LinearLayout) findViewById(R.id.ror_LL);
        edge = (LinearLayout) findViewById(R.id.edge_LL);
        burst = (LinearLayout) findViewById(R.id.burst_LL);
        impact = (LinearLayout) findViewById(R.id.impact_LL);

        // -------------Themes------------------------------
        blue_theme = (LinearLayout) findViewById(R.id.blue_theme_LL);
        orange_theme = (LinearLayout) findViewById(R.id.orange_theme_LL);
        green_theme = (LinearLayout) findViewById(R.id.green_theme_LL);

        // ------------Brightness----------------------------
        black_brigthness = (LinearLayout) findViewById(R.id.black_brigthness_LL);
        white_brightness = (LinearLayout) findViewById(R.id.white_brigthness_LL);

        // --------------On Click Events-------------------

        roar.setOnClickListener(this);
        edge.setOnClickListener(this);
        burst.setOnClickListener(this);
        impact.setOnClickListener(this);

        // -----------Theme-------------------------------------
        blue_theme.setOnClickListener(this);
        orange_theme.setOnClickListener(this);
        green_theme.setOnClickListener(this);

        // ------------------Brightness--------------------------
        black_brigthness.setOnClickListener(this);
        white_brightness.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
        case R.id.ror_LL:

            startActivity(new Intent(Setting.this, MainActivity.class));

            break;

        case R.id.edge_LL:

            startActivity(new Intent(Setting.this, MainActivity.class));




            break;
        case R.id.burst_LL:

            startActivity(new Intent(Setting.this, MainActivity.class));

            break;

        case R.id.impact_LL:

            startActivity(new Intent(Setting.this, MainActivity.class));

            break;  

        case R.id.blue_theme_LL:

            Intent i = new Intent(Setting.this,
                    MainActivity.class);
                i.putExtra("color", "blue");

            startActivity(i);


            break;

        case R.id.orange_theme_LL:
            Intent i2 = new Intent(Setting.this,
                    MainActivity.class);
                i2.putExtra("color", "orange");

            startActivity(i2);

            break;

        case R.id.green_theme_LL:
            Intent i3 = new Intent(Setting.this,
                    MainActivity.class);
                i3.putExtra("color", "green");

            startActivity(i3);

            break;
        case R.id.black_brigthness_LL:

            Intent black_britness = new Intent(Setting.this,
                    MainActivity.class);
            black_britness.putExtra("bright", "black");
            startActivity(black_britness);

              SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
              SharedPreferences.Editor editor = preferences.edit();
              editor.putString("Name","Harneet");
              editor.commit();


            isblackBrightness = true ; 
            Log.e("Black--","Black=="+isblackBrightness);

            break;
        case R.id.white_brigthness_LL:
            Intent white_britness = new Intent(Setting.this,
                    MainActivity.class);
            white_britness.putExtra("bright", "white");
            startActivity(white_britness);
            isblackBrightness = false;
            Log.e("white--","White=="+isblackBrightness);

            SharedPreferences preferences1 = PreferenceManager.getDefaultSharedPreferences(this);
              SharedPreferences.Editor editor1 = preferences1.edit();
              editor1.putString("Name","Arun");
              editor1.commit();


            break;

         }
    }
}

ウィジェットを設定する必要があるかどうかにかかわらず、これを行う方法がわかりません。

4

2 に答える 2

5

キーボードが表示されると、フレームワークは を呼び出しますonStartInputView。その関数をプログラムして、共有設定の値を確認し、キーボード ビューで色/テーマを適切に設定できます。

于 2013-08-12T06:10:24.577 に答える