[英]Changing the Title and EditText color in androidx.preference.EditTextPreference
我在這個主題上發現了一些類似的問題,但它適用於support version
,而不適用於androidx
。 我無法在 androidx 上進行此更改。 但是在以前的支持版本上已經有解決方案了。 誰能給我一些關於如何在EditTextPreference中更改標題和 editetext 字段文本顏色的指示? 目前顏色為白色,背景也為白色,文本不可見。
這是我已經在 stackoverflow 上找到的解決方案,但我無法使用。我想將白色文本顏色更改為黑色。 謝謝你。
在 Murphybro2 解決方案的線程中,我們也得到了 androidx https://stackoverflow.com/a/58836953的解決方案
您可以通過提供自定義主題樣式來更改應用程序使用的 AlertDialogStyle
<style name="AppTheme.Settings">
<!-- This will change the opening dialogs for EditTextPreference -->
<item name="alertDialogStyle">@style/Theme.example.AlertTheme</item>
</style>
<style name="Theme.example.AlertTheme" parent="">
<item name="android:textViewStyle">@style/Theme.AlertTextStyle</item>
<item name="android:textColor">@color/pink</item>
<item name="android:editTextBackground">@color/pink</item>
<item name="android:windowMinWidthMajor">@dimen/abc_dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">@dimen/abc_dialog_min_width_minor</item>
<item name="android:windowIsFloating">true</item>
</style>
<style name="Theme.AlertTextStyle" parent="Theme.example">
<item name="android:textColorPrimary">@color/gray</item>
</style>
對我來說最重要的一個是“windowIsFloating">true 因為否則窗口會粘在屏幕的頂部對我來說只添加額外的 textViewStyle 有助於更改對話框中的頂部文本,但我認為這是因為我的例子主題。
AndroidX 版本的 EditTextPreference 允許您在自己的綁定事件上設置監聽器。 例如,您可以在 androidx.preference.PreferenceFragmentCompat class 的 onCreatePreferences 中使用它
override fun onCreatePreferences() {
super.onCreatePreferences()
findPreference<EditTextPreference>("my_preference_key")?.let {
it.setOnBindEditTextListener { editText ->
editText.setTextColor(Color.BLACK)
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.