【问题标题】:Create circular looking drawable in android在android中创建圆形的drawable
【发布时间】:2016-08-06 16:04:13
【问题描述】:

我想在android java中创建一个圆形颜色填充的drawable,里面有一个字母。我想动态设置字母和颜色。任何想法如何创建它?

【问题讨论】:

    标签: java android xml drawable


    【解决方案1】:

    试试这个。https://github.com/amulyakhare/TextDrawable 在此存储库中,您可以将文本放入可绘制对象中

    【讨论】:

      【解决方案2】:

      像这样创建你的 TextView(这个以文本为中心):

      <TextView
          android:id="@+id/mTextView"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:gravity="center"
          android:layout_centerVertical="true"
          android:background="@drawable/shape_circle">
      </TextView>
      

      你的形状是这样的:

      <shape xmlns:android="http://schemas.android.com/apk/res/android"
          android:shape="oval">
          <solid
              android:color="@color/circleColor">
          </solid>
          <size
              android:width="@dimen/circleSize"
              android:height="@dimen/circleSize"
              />
      </shape>
      

      然后您可以像往常一样使用 mTextView.setText() 动态设置 TextView 中的文本。

      要动态更改颜色,请查看here

      【讨论】:

        猜你喜欢
        • 2019-07-28
        • 2020-12-24
        • 2019-02-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多