欢迎转帖,但请注明地址:http://blog.youkuaiyun.com/ethan_xue/ 谢谢
最近因为项目需要,更改EditText被选中时的图片,网络搜索未果,于是查看源代码
EditText代码里没什么东西,于是猜测在其父类TextView中,很快发现这样一段代码
- int mTextSelectHandleLeftRes;
- int mTextSelectHandleRightRes;
- int mTextSelectHandleRes;
- Drawable mSelectHandleLeft;
- Drawable mSelectHandleRight;
- Drawable mSelectHandleCenter;
- case com.android.internal.R.styleable.TextView_textSelectHandleLeft:
- mTextSelectHandleLeftRes = a.getResourceId(attr, 0);
- break;
看到R.styleable.TextView_textSelectHandleLeft,果断去查看res文件,呵呵,果然就是他
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>
看到?android:attr/textSelectHandleLeft去查看attr.xml,结果有以下代码
- <!-- 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" />
- <!-- 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>
到此终于找到图片了,替换掉后的效果
然后看到选中的字的背景是黄色的,怎样改变呢?
源码里
- /**
- * 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();
- }
- }
效果如图