android 改变TextView和EditText文字选中效果
2012-10-28 20:59
555 查看
欢迎转帖,但请注明地址:http://blog.csdn.net/ethan_xue/ 谢谢
最近因为项目需要,更改EditText被选中时的图片,网络搜索未果,于是查看源代码
EditText代码里没什么东西,于是猜测在其父类TextView中,很快发现这样一段代码
看到R.styleable.TextView_textSelectHandleLeft,果断去查看res文件,呵呵,果然就是他
styles.xml里
看到?android:attr/textSelectHandleLeft去查看attr.xml,结果有以下代码
到此终于找到图片了,替换掉后的效果
然后看到选中的字的背景是***的,怎样改变呢?
源码里
效果如图
最近因为项目需要,更改EditText被选中时的图片,网络搜索未果,于是查看源代码
EditText代码里没什么东西,于是猜测在其父类TextView中,很快发现这样一段代码
int mTextSelectHandleLeftRes; int mTextSelectHandleRightRes; int mTextSelectHandleRes; Drawable mSelectHandleLeft; Drawable mSelectHandleRight; Drawable mSelectHandleCenter;看名字就猜到是这个了,google写的代码就是漂亮,根据mTextSelectHandleLeftRes找到这段代码
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" />到此只能说明有这个属性,那杯具了,只有个style,图片文件在哪里啊?于是使用强大的notepad++的查找功能,ctrl+f--文件查找--textSelectHandleLeft结果发现public.xml里和themes.xml里都有,themes.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>
到此终于找到图片了,替换掉后的效果
然后看到选中的字的背景是***的,怎样改变呢?
源码里
/** * 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(); } }于是我们只要设置这个方法就可以了
效果如图
相关文章推荐
- android 改变TextView和EditText文字选中效果
- android 改变TextView和EditText文字选中效果
- android TextWatcher 监听textview和edittext的文字输入改变
- Android中EditText和AutoCompleteTextView设置文字选中颜色方法
- android TextView 首行缩进与部分文字改变颜色大小效果
- android EditText中如何将输入框中的文字选中?
- Android Textview实现文字颜色渐变效果
- android textview改变部分文字的颜色
- Android中继承TextView实现文字的跑马灯效果
- android如何改变editText控件中部分文字的格式
- android显示TextView文字的倒影效果
- TextView的点击效果---文字颜色改变
- android中TextView 添加ClickableSpan后点击选中文字背景变色问题
- 关于android中改变TextView背景颜色以及文字颜色的问题
- AndroidStudio——TextView文字左右滚动(跑马灯效果)无效解决办法
- android - TextView单行显示...或者文字左右滚动(走马灯效果)
- Android O新特性之Autosizing TextViews(随着TextView宽高而自动改变文字大小)
- Android TextView(EditView)文字底部或者中间 加横线
- android 根据EditText 内容,改变TextView显示
- android - TextView单行显示...或者文字左右滚动(走马灯效果)