Is it possible to make such a TextView ? If so, where to start?
Example:
Look article on Habré or MagicTextView library.
Or play with the shadows .
Having viewed article on Habré , I redid it for TextView .
OutlineTextView.java:
package com.example.outlinetextview; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint.Join; import android.graphics.Paint.Style; import android.text.TextPaint; import android.util.AttributeSet; import android.widget.TextView; import com.example.outlinetextview.R; public class OutlineTextView extends TextView { private int strokeColor= Color.TRANSPARENT; private int strokeWidth=2; public OutlineTextView(Context context) { super(context); } public OutlineTextView(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.OutlineTextView); strokeColor = a.getColor(R.styleable.OutlineTextView_textStrokeColor, strokeColor); strokeWidth = a.getDimensionPixelSize(R.styleable.OutlineTextView_textStrokeWidth, strokeWidth); a.recycle(); } public void onDraw(Canvas canvas) { final ColorStateList textColor = getTextColors(); TextPaint paint = this.getPaint(); paint.setStyle(Style.STROKE); paint.setStrokeJoin(Join.ROUND); paint.setStrokeMiter(10); this.setTextColor(strokeColor); paint.setStrokeWidth(strokeWidth); super.onDraw(canvas); paint.setStyle(Style.FILL); setTextColor(textColor); super.onDraw(canvas); } } attrs:
<?xml version="1.0" encoding="utf-8"?> <resources> .... <declare-styleable name="OutlineTextView"> <attr name="textStrokeColor" format="color"/> <attr name="textStrokeWidth" format="dimension"/> </declare-styleable> .... </resources> example.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" xmlns:app="http://schemas.android.com/apk/res-auto" android:background="@null" android:gravity="center" android:orientation="vertical"> <com.example.outlinetextview.OutlineTextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@null" android:gravity="center" android:textSize="15sp" android:textColor="#2196F3" app:textStrokeWidth="5sp" app:textStrokeColor="#FFFFFF"/> </LinearLayout> Result:
PS I hope someone thread is useful :)
Source: https://ru.stackoverflow.com/questions/541785/
All Articles