0

アプリケーションにカスタム キーボードがあり、ユーザー設定に基づいて実行時にテキストの色を変更したいと考えています。XML で KeyTextColor を設定することはできますが、プログラムで設定する属性はありません。これは私がXmlで設定する方法です:

<?xml version="1.0" encoding="utf-8"?>
<app:android.inputmethodservice.KeyboardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/keyboard"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    android:keyBackground="@drawable/key_background"
    android:keyPreviewHeight="@dimen/dp_0"
    android:keyTextSize="40sp"
    android:keyTextColor="#00C853">//I set green text color here
</app:android.inputmethodservice.KeyboardView>

プログラムから同じ KeyTextColor を設定したい。何か案は?

4

1 に答える 1

1

これはまさにあなたが尋ねたものではありませんが、私の問題を解決しました。レイアウトフォルダー(質問のような)に異なるkeyboard.xmlを追加することで、さまざまなテーマを定義できます。そしてそれらをランタイムに変更します。

@Override
public View onCreateInputView() {

    ...

    int theme_id=keyboard_prefs.getKeyboardThemeID();

    if(theme_id== KeyboardConstants.KEYBOARD_THEME_DARK_ID)
        mInputView=(LatinKeyboardView) getLayoutInflater().inflate(R.layout.keyboard_dark, null);
    else //if(theme_id==2)
        mInputView=(LatinKeyboardView) getLayoutInflater().inflate(R.layout.keyboard_light, null);

    }    
于 2018-02-05T08:42:23.980 に答える