【发布时间】:2016-09-13 08:00:55
【问题描述】:
如何在自定义按钮(使用 res/drawable 中的 png)上显示文本视图?
我正在尝试为 android 穿戴的可穿戴方形手表创建 UI。 我创建了自定义背景来更改我希望布局包含的两个按钮的外观。 当我在布局中添加一个 textview 时,它总是放在 Button 下,并且永远不可见。
我已经搜索过解决方案,但通常问题是人们使用了错误的布局。我已经尝试过框架和相对布局,它们都应该将其内容堆叠在一起,但没有。
虽然我可以在按钮本身中使用文本字段,但我宁愿有一个专用的 textview 用于写入里面的文本。但我就是想不通是什么问题。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text"
android:textColor="#ffffff"
android:layout_gravity="center"/>
<Button
android:id="@+id/wearable_alarm_button"
android:layout_width="wrap_content"
android:background="@drawable/red_button"
android:layout_height="wrap_content" />
<Button
android:layout_width="130dp"
android:layout_height="120dp"
android:background="@drawable/blue_button"
android:id="@+id/wearable_timer_button"
android:layout_gravity="right|bottom" />
</FrameLayout>
【问题讨论】:
-
也分享你的蓝色和红色按钮
-
不知道你为什么想要它。 red_buttonblue_button
标签: android android-layout android-studio wear-os