相关疑难解决方法(0)

如何在Android中创建虚线/虚线?

我想做一个虚线.我现在正在使用这个实线:

LinearLayout divider = new LinearLayout( this );
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, 2 );
divider.setLayoutParams( params );
divider.setBackgroundColor( getResources().getColor( R.color.grey ) );
Run Code Online (Sandbox Code Playgroud)

我需要这样的东西,但点缀而不是坚实.我想避免在透明布局和实体布局之间交替进行数百种布局.

android

231
推荐指数
10
解决办法
18万
查看次数

如何在Android中使用另一种颜色获得UnderlineSpan?

我希望在IDE中看起来像错误的Spannable - 用另一种颜色加下划线.

我试图创建ColorUnderlineSpan扩展android的类UnderlineSpan,但它使所有文本成为另一种颜色(我只需要添加彩色下划线):

/**
 * Underline Span with color
 */
public class ColorUnderlineSpan extends android.text.style.UnderlineSpan {

    private int underlineColor;

    public ColorUnderlineSpan(int underlineColor) {
        super();
        this.underlineColor = underlineColor;
    }

    @Override
    public void updateDrawState(TextPaint ds) {
        super.updateDrawState(ds);
        ds.setColor(underlineColor);
    }
}
Run Code Online (Sandbox Code Playgroud)

我也找到了DynamicDrawableSpan课程,但我看不到画布边界要画.

使用带有bounds参数的抽象绘制方法获得任何Spannable impl会很棒.

html user-interface android spannable

4
推荐指数
1
解决办法
1389
查看次数

android,如何在edittext中绘制虚线

我参考了这个链接:如何在Android中创建虚线/虚线?,并使用DashPathEffect.但这对我不起作用?为什么?我的代码:

public class NoteEditText extends EditText {
    private Paint mPaint;

    public NoteEditText(Context context) {
        super(context);
    }

    public NoteEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        mPaint = new Paint();
        mPaint.setStrokeWidth(1);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setColor(Color.DKGRAY);
        PathEffect effects = new DashPathEffect(new float[]{5,5,5,5},1);  
        mPaint.setPathEffect(effects);
    }

    @Override
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        int height = this.getHeight();
        int lineHeight = this.getLineHeight();
        int lineNum = height / lineHeight;
        L.l("line count: " + lineNum);
        for (int i = 0; i < lineNum; i++) {
            int …
Run Code Online (Sandbox Code Playgroud)

android draw dotted-line ondraw android-edittext

3
推荐指数
1
解决办法
5404
查看次数