如何在Android中使用的TextView来显示通知文本文本、通知、如何在、TextView

2023-09-12 23:49:42 作者:神乐

我想在我的Andr​​oid application.I显示文字与圆形知道它是与custome的TextView做,但可以将某些哥们给我正确的codeI上午还附上图片,我想这类型的样子。

I want to show text with circular shape in my android application.I know it is done with custome textview but can some buddy give me proper code.I am also attaching image which type of look i want.

推荐答案

你可以试试这个测试和充分的工作code:

you can try this tested and full working code :

 public class MainActivity extends Activity {
      @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
       setContentView(new GraphicsView(this));}

  static public class GraphicsView extends View {
     private static final String QUOTE = "This is a curved text";
     private Path circle;
     private Paint cPaint;
     private Paint tPaint;

 public GraphicsView(Context context) {
  super(context);

  int color = Color.argb(127, 255, 0, 255);

  circle = new Path();
  circle.addCircle(230, 350, 150, Direction.CW);

  cPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  cPaint.setStyle(Paint.Style.STROKE);
  cPaint.setColor(Color.LTGRAY);
  cPaint.setStrokeWidth(3);

  setBackgroundResource(R.drawable.heart);

  tPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  tPaint.setStyle(Paint.Style.FILL_AND_STROKE);
  tPaint.setColor(Color.BLACK);
  tPaint.setTextSize(50);}


  @Override
     protected void onDraw(Canvas canvas) {
     canvas.drawTextOnPath(QUOTE, circle, 485, 20, tPaint);} 
                                        } }

输出将是:

希望这有助于。