【问题标题】:How to Create Line Drawable On Android如何在 Android 上创建 Line Drawable
【发布时间】:2016-05-02 05:42:25
【问题描述】:

如何在 Android 上创建 Drawable 如下所示:

删除

【问题讨论】:

标签: android android-drawable xml-drawable


【解决方案1】:

对于单个单词,我们可以使用 drawable。 以下是示例:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="false"><shape android:shape="line">
            <stroke android:width="2dp" android:color="#ffffff" />
        </shape>
    </item>

</selector>

下面的多行使用:-

TextView tv=(TextView) v.findViewById(android.R.id.text1);
tv.setPaintFlags(tv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

使用您的参考而不是“tv”

【讨论】:

  • @Ahmad 很高兴为您提供帮助。
【解决方案2】:

你可以这样做:

以编程方式:

 TextView tv = (TextView) findViewById(R.id.mytext);
    tv.setText("Remove");
    tv.setPaintFlags(tv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

来自 xml 文件:

    <RelativeLayout
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           >
     <TextView
           android:id="@+id/textView2"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="Remove"
           />
     <View
           android:layout_width="fill_parent"
           android:layout_height="1dp"
           android:background="@color/black"
           android:layout_centerVertical="true"
            />
</RelativeLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-11
    • 1970-01-01
    • 2011-06-16
    • 2012-01-11
    • 1970-01-01
    • 2016-10-19
    • 2019-07-28
    相关资源
    最近更新 更多