英文:
Changing TextInputEditText's select mode color
问题
我正在使用TextInputLayout和TextInputEditText。我找不到更改这个紫色的方法。我也搜索过,但找不到很多信息。我该如何更改它?
英文:
I am using TextInputLayout and TextInputEditText. I cant find a way to change this purple color. I searched about it too but i cant find so much. How can i change it?
答案1
得分: 2
你需要为你的应用添加一些样式。
在styles.xml
中(或者你的应用主题文件的名称),你需要为应用的主题设置textInputStyle
:
<style name="AppTheme" parent="Theme.Material3.DayNight.NoActionBar">
...
<item name="textInputStyle">@style/Widget.App.TextInputLayout.OutlinedBox</item>
...
</style>
然后,你需要为你的TextInputLayout
创建一个样式(在我的情况下,父样式是OutlinedBox
,但你可以选择任何其他样式),并将android:textColorHighlight
和android:colorControlActivated
设置为你想要的颜色。textColorHighlight
设置所选文本的背景颜色,而colorControlActivated
设置文本周围两个“持有者”的颜色:
<style name="Widget.App.TextInputLayout.OutlinedBox" parent="Widget.Material3.TextInputLayout.OutlinedBox">
<item name="android:textColorHighlight">#ff0000</item>
<item name="android:colorControlActivated">#00ff00</item>
</style>
通过这些操作,你将看到以下结果:
英文:
You need to add a little bit of styling to your app.
In styles.xml
(or what is the name of your app's main theme file) you need to set textInputStyle
for your app's theme:
<style name="AppTheme" parent="Theme.Material3.DayNight.NoActionBar">
...
<item name="textInputStyle">@style/Widget.App.TextInputLayout.OutlinedBox</item>
...
</style>
Then you need to create a style for your TextInputLayout
(in my case the parent style is OutlinedBox
but you can choose any other style you want) and set android:textColorHighlight
and android:colorControlActivated
to your desired color. textColorHighlight
sets the background color of selected text and colorControlActivated
sets the color of two "holders" around the text:
<style name="Widget.App.TextInputLayout.OutlinedBox" parent="Widget.Material3.TextInputLayout.OutlinedBox">
<item name="android:textColorHighlight">#ff0000</item>
<item name="android:colorControlActivated">#00ff00</item>
</style>
And after these manipulations you'll see the following result:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论