<分区>
使用这段代码,我可以显示带有 TextView 的 TextView :
holder.discounttext.setText("MRP " + rupee + discountcost);
holder.discounttext.setPaintFlags(holder.discounttext.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
欲望屏幕:
请告诉我如何设置红色的打击色?
标签 android
<分区>
使用这段代码,我可以显示带有 TextView 的 TextView :
holder.discounttext.setText("MRP " + rupee + discountcost);
holder.discounttext.setPaintFlags(holder.discounttext.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
欲望屏幕:
请告诉我如何设置红色的打击色?
最佳答案
制作一个自定义的TextView
class CustomTextView extends TextView {
public Paint paint;
public boolean addStrike = false;
public CustomTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomTextView(Context context) {
super(context);
init(context);
}
public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context);
}
private void init(Context context) {
paint = new Paint();
paint.setColor(Color.RED);
paint.setStrokeWidth(getResources().getDisplayMetrics().density * 1);
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
if (addStrike) {
canvas.drawLine(0, getHeight() / 2, getWidth(),
getHeight() / 2, paint);
}
}
}
为了添加 stoke 你可以调用
myCustomTextView.addStrike = true;
myCustomTextView.invalidate();
要取消罢工,您只需调用
myCustomTextView.addStrike = false;
myCustomTextView.invalidate();
关于android - 如何在 Android 中设置红色 TextView 的删除线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34282634/
相关文章:
android - 如何从android中的搜索栏更改设备音量
android - TabLayout 中的居中 Activity 选项卡
android - 仅将视频加载到 VideoView 中而不立即播放
android - 在 Xamarin.Android 中通过 MVVMCross 绑定(bind) OxyPlot
android - 从传入消息 (SMS) 中获取 IMSI 号码或目标电话号码
android - 有没有办法直接使用 SpeechRecognizer API 进行语音输入?
Android 相对布局 : how to alignParentBottom when wrapped in a ScrollView?