简体   繁体   English

为什么自定义绘图未显示在 android 中

[英]Why custom drawable not showing in android

TextView is added to the screen 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 is: information_underline 可绘制是:

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

Check the @Suraj answer.检查@Suaj 答案。
An alternative could be to use a TextInputLayout in the Material Component Library with a OutlinedBox style.另一种方法是在材质组件库中使用带有 OutlinedBox 样式的TextInputLayout

Something like:就像是:

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

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

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

在此处输入图像描述

Drawable you have created is not the right way to do that and use the below code to draw anything in bottom of textview您创建的 Drawable 不是正确的方法,请使用以下代码在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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM