【问题标题】:Why custom drawable not showing in android为什么自定义drawable没有在android中显示
【发布时间】:2019-10-07 14:43:46
【问题描述】:

TextView 被添加到屏幕

<TextView
        android:id="@+id/eventDetail_SpecialInfos"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="4dp"
        android:fontFamily="@font/source_sans_pro"
        android:text="Special Info"
        android:drawableBottom="@drawable/information_underline"
        android:textColor="@color/colorBlack"
        android:textSize="14dp" />

information_underline drawable 是:

<stroke
    android:width="20dp"
    android:color="@color/colorBlack" />

【问题讨论】:

  • Stroke 只是 ShapeDrawable 的一个参数。它本身并不是一个可绘制对象。
  • 这也不是你给文本下划线的方式..

标签: android textview android-textinputlayout material-components material-components-android


【解决方案1】:

检查@Suraj 的答案。
另一种方法是在 Material Component Library 中使用带有 OutlinedBox 样式的TextInputLayout

类似:

<com.google.android.material.textfield.TextInputLayout
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
    ..>

    <com.google.android.material.textfield.TextInputEditText
        ../>

</com.google.android.material.textfield.TextInputLayout>

【讨论】:

    【解决方案2】:

    您创建的可绘制对象不是正确的方法,请使用以下代码在textview 底部绘制任何内容

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle" >
    
        <size
            android:height="1dp"
            android:width="100dp" />
    
        <solid android:color="@android:color/black" />
    
    </shape>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-17
      相关资源
      最近更新 更多