更改TextInputEditText的选择模式颜色

huangapple go评论57阅读模式
英文:

Changing TextInputEditText's select mode color

问题

我正在使用TextInputLayout和TextInputEditText。我找不到更改这个紫色的方法。我也搜索过,但找不到很多信息。我该如何更改它?

英文:

更改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:textColorHighlightandroid: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>

通过这些操作,你将看到以下结果:

更改TextInputEditText的选择模式颜色

英文:

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:

&lt;style name=&quot;AppTheme&quot; parent=&quot;Theme.Material3.DayNight.NoActionBar&quot;&gt;
	...
	&lt;item name=&quot;textInputStyle&quot;&gt;@style/Widget.App.TextInputLayout.OutlinedBox&lt;/item&gt;
	...
&lt;/style&gt;

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:

&lt;style name=&quot;Widget.App.TextInputLayout.OutlinedBox&quot; parent=&quot;Widget.Material3.TextInputLayout.OutlinedBox&quot;&gt;
	&lt;item name=&quot;android:textColorHighlight&quot;&gt;#ff0000&lt;/item&gt;
	&lt;item name=&quot;android:colorControlActivated&quot;&gt;#00ff00&lt;/item&gt;
&lt;/style&gt;

And after these manipulations you'll see the following result:

更改TextInputEditText的选择模式颜色

huangapple
  • 本文由 发表于 2023年4月19日 17:12:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76052725.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定