我的应用程序中有一个自定义键盘,希望根据用户偏好在运行时更改文本颜色。我可以在 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。有任何想法吗?
这不完全是你问的,但它解决了我的问题。您可以通过在布局文件夹中添加不同的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);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)