【问题标题】:Text not showing on my Button- Android studio我的 Button-Android 工作室上未显示文本
【发布时间】:2020-12-08 12:09:56
【问题描述】:

我是 Android Studio 的新手,我需要在此处的 Button 上写一些东西,但没有显示文字,我该怎么做才能解决这个问题?

请注意,代码中显示的LinearLayout 位于另一个更大的LinearLayout 中。

<LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">
    <Button
                    android:id="@+id/datee"
                    android:layout_width="150dp"
                    android:layout_height="50dp"
                    android:layout_marginTop="20dp"
                    android:background="@drawable/yellow_border"
                    android:text="hiiii"
                    android:gravity="center_horizontal"
                    android:paddingHorizontal="10dp"
                    android:textSize="15sp"></Button>
    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="10dp"
                        android:layout_marginTop="25dp"
                        android:text="Auction date: "
                        android:id="@+id/done"></TextView>
</LinearLayout>

【问题讨论】:

  • 尝试调整按钮的内边距和边距
  • 可以分享整个xml文件吗?
  • @tataelm 代码太长我无法在评论中发布它
  • 尝试删除背景属性,即 android:background="@drawable/yellow_border" 。如果可行,您可以使用材质轮廓按钮样式来设置黄色边框。
  • 我试过上面的代码,它工作正常。当然我不能测试 Yellow_border 背景。你能发送一张图片在你的设备上的样子吗?

标签: android android-studio android-layout button


【解决方案1】:

你可以使用这样的东西

 <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical">

            <Button
                android:id="@+id/datee"
                android:layout_width="150dp"
                android:layout_height="50dp"
                android:layout_marginTop="20dp"
                android:text="hiiii"
                android:gravity="center_horizontal"
                android:textSize="15sp" />

            </LinearLayout>

并尝试更改android:background="@drawable/yellow_border"

因为你里面可能有一些填充

【讨论】:

    猜你喜欢
    • 2016-06-10
    • 1970-01-01
    • 2017-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多