Implementation code of text background modification after Android selector gets focus

Time:2021-2-20

1. Modify the text background after getting the focus

【1】 Selector status selector (BG)_ check_ Three (store res – color)) resource file, otherwise it doesn’t work

【2】 In focus state – android:state_ Focused = “true” (get focus)

【3】 android:state_ Focused = “true” must be placed on the first line, otherwise it will not take effect

2. Realize demo

【1】 Implementation effect:

 

【2】 Implementation code

Create selector file

 

The content of the selector file under the color file


<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/colorPrimary" android:state_focused="true"/>
<item android:color="@color/colorAccent" />
</selector> 

XML file to call: android:textColor= “@color/bg_ edittext_ “One” has the background of focus modification

<EditText
  android:textColor="@color/bg_edittext_one"
  android:layout_width="match_parent"
  android:layout_height="45dp"
  android:text= Focus style: change background color and font color at the same time
  android:gravity="center"
  />

summary

The above is the implementation code of Android selector text background modification after getting focus introduced by Xiaobian. I hope it can help you. If you have any questions, please leave me a message and Xiaobian will reply you in time. Thank you very much for your support to developer!
If you think this article is helpful to you, please reprint, please indicate the source, thank you!

Recommended Today

What knowledge points have I gained by using vue3.0 (1)

The front-end development is full of flowers, and one skill is not yet mature.At a loss, I don’t know what to do. I pay close attention to the small editor’s success. I feel very busy recently. I don’t have much time to write articles. Today’s article is mainly about my early studyVue3.0Some of the notes […]