Android的 - 方式出现接壤TextView的文字?文字、方式、Android、TextView

2023-09-12 02:01:08 作者:冭儍冭迗眞

有没有办法出现在TextView的接壤文字?

Is there a way to appear bordered text on the TextView ?

推荐答案

我会建议延长的 TextView中 请参见 Android的定制组件指南

I would suggest to extend TextView See Android Custom Component Guide

package samples.test;
public class MyTextView extends TextView {
    public MyTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public MyTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

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

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Rect rect = new Rect();
        Paint paint = new Paint();
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.WHITE);
        paint.setStrokeWidth(3);
        getLocalVisibleRect(rect);
        canvas.drawRect(rect, paint);       
    }
}

比布局XML使用它:

Than use it in layout xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <samples.test.MyTextView android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:text="@string/hello" />
</LinearLayout>
 
精彩推荐
图片推荐