Please post, but please note the address: http://blog.csdn.net/ethan_xue/ Thank you
Recently, due to project requirements, the image selected when edittext is changed and the network search fails, so you can view the source code.
There is nothing in the edittext code, so I guess that in the textview of its parent class, I soon found such a piece of code
int mTextSelectHandleLeftRes; int mTextSelectHandleRightRes; int mTextSelectHandleRes; Drawable mSelectHandleLeft; Drawable mSelectHandleRight; Drawable mSelectHandleCenter;
The code written by Google is pretty. Find This code according to mtextselecthandleleftres.
case com.android.internal.R.styleable.TextView_textSelectHandleLeft: mTextSelectHandleLeftRes = a.getResourceId(attr, 0); break;
You can see R. styleable. textview_textselecthandleleft and choose to view the res file.
In styles. xml
<style name="Widget.TextView"> <item name="android:textAppearance">?android:attr/textAppearanceSmall</item> <item name="android:textSelectHandleLeft">?android:attr/textSelectHandleLeft</item> <item name="android:textSelectHandleRight">?android:attr/textSelectHandleRight</item> <item name="android:textSelectHandle">?android:attr/textSelectHandle</item> </style>
See? Android: ATTR/textselecthandleleft to view ATTR. xml. The result is as follows:
<!-- Reference to a drawable that will be used to display a text selection anchor on the left side of a selection region. --> <attr name="textSelectHandleLeft" />
This attribute can only be described here. The cup has only one style. Where is the image file? Therefore, using the powerful notepad ++ search function, CTRL + f -- file search -- textselecthandleleft found public. in XML and themes. themes. this is what is written in XML.
<!-- Text selection handle attributes --> <item name="textSelectHandleLeft">@android:drawable/text_select_handle_left</item> <item name="textSelectHandleRight">@android:drawable/text_select_handle_right</item> <item name="textSelectHandle">@android:drawable/text_select_handle_middle</item> <item name="textSelectHandleWindowStyle">@android:style/Widget.TextSelectHandle</item>
The image is finally found. The effect after replacement
Then we can see that the selected word background is yellow. How can we change it?
Source code
/** * Sets the color used to display the selection highlight. * * @attr ref android.R.styleable#TextView_textColorHighlight */ @android.view.RemotableViewMethod public void setHighlightColor(int color) { if (mHighlightColor != color) { mHighlightColor = color; invalidate(); } }
So we only need to set this method.
Effect