【问题标题】:how can I add button in Textview-android studio layout editor如何在 Textview-android studio 布局编辑器中添加按钮
【发布时间】:2021-04-12 03:53:42
【问题描述】:

button"start" is in Textview

我该怎么做?

【问题讨论】:

  • 从你的图片看,它看起来在'下面' TextView 不是'in'。

标签: android-studio android-layout android-layout-editor


【解决方案1】:

如果您想要一个带有圆形 textView 的按钮,那么我就是这样做的。请注意,我在这里使用com.google.android.material 以获得我想要的最快结果。

<com.google.android.material.button.MaterialButton
    android:id="@+id/button"
    android:backgroundTint="@android:color/holo_red_light"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="24dp"
    android:text="start"
    app:cornerRadius="16dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

这就是它在我的 IDE 上的样子。

【讨论】:

    【解决方案2】:

    您可以简单地使用Button 组件。但是如果你想拿TextView 那么:

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/start_btn_bg"
            android:text="start"
            android:paddingHorizontal="30dp"
            android:paddingVertical="10dp"/>
    

    您可以通过使自定义可绘制来设置背景。 下面是自定义drawable:

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient android:startColor="@color/color_red_error"
        android:centerColor="@color/color_red_error"
        android:endColor="@color/colorAccent"/>
    <corners android:radius="20dp" />
    

    【讨论】:

    • 嗨,我想你也可以在这里添加你的start_btn_bgsn-p :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-31
    • 1970-01-01
    相关资源
    最近更新 更多