如何在Android中以编程方式更改形状的笔触宽度?

前端之家收集整理的这篇文章主要介绍了如何在Android中以编程方式更改形状的笔触宽度?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这是circle.xml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:shape="oval">
  4. <solid android:color="#00000000"/>
  5. <padding android:left="30dp" android:top="30dp"
  6. android:right="30dp" android:bottom="30dp" />
  7. <stroke android:color="#439CC8" android:width="7dp" />
  8. </shape>

这是我的代码

  1. textview.setBackgroundResource(R.drawable.circle);

我想在我的java代码中更改笔触粗细.如何以编程方式更改它?

解决方法

您可能需要以编程方式创建它
  1. ShapeDrawable circle = new ShapeDrawable( new OvalShape() );

你需要在此之后设置属性,(填充,颜色等)然后改变它的笔划

  1. circle.getPaint().setStrokeWidth(12);

然后将其设置为视图的背景

  1. textview.setBackgroundDrawable(circle);

猜你在找的Android相关文章