【问题标题】:how to give underline color different and textcolor different to a Textview [duplicate]如何为Textview赋予不同的下划线颜色和不同的textcolor [重复]
【发布时间】:2016-07-04 20:13:58
【问题描述】:
我正在尝试这个,但它不适合我
Paint p = new Paint();
p.setColor(ContextCompat.getColor(textView.getContext(),android.R.color.holo_red_dark));
textView.setPaintFlags(p.getColor());
textView.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);
【问题讨论】:
标签:
android
android-layout
【解决方案1】:
试试这个方法
Paint p = new Paint();
p.setColor(ContextCompat.getColor(this,android.R.color.holo_red_dark));
p.setflags(Paint.UNDERLINE_TEXT_FLAG);
textView.setPaintFlags(p.getFlags());
更多信息请参见this 问题。
【解决方案2】:
edittext.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_IN);
【解决方案3】:
在 drawable 文件夹中创建一个 under_line.xml 文件,然后像这样设置你的 textview 背景 android:background="@drawable/under_line"
将此 xml 添加到您的可绘制文件夹 uder_line.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:bottom="-15dp">
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:pivotX="0.5"
android:pivotY="0.5"
android:toDegrees="0">
<shape android:shape="line">
<stroke
android:width="1dp"
android:color="@android:color/holo_red_dark" />
</shape>
</rotate>
</item></layer-list>
然后像这样设置你的布局文本视图背景
android:background="@drawable/under_line"