android文本未显示在按钮中
当我开始使用android时,这种情况经常发生。按钮元素中的文本未完全显示。有什么不对劲?我试过文本方向、对齐、重力,但都不起作用 其背后的代码是:android文本未显示在按钮中,android,android-layout,android-relativelayout,Android,Android Layout,Android Relativelayout,当我开始使用android时,这种情况经常发生。按钮元素中的文本未完全显示。有什么不对劲?我试过文本方向、对齐、重力,但都不起作用 其背后的代码是: <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView1" androi
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:text="@string/latestButtonString"
android:background="@drawable/roundbutton" />
请帮忙,非常感谢
更新:这是roundbutton.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<!-- you can use any color you want I used here gray color-->
<solid android:color="#ABABAB"/>
<corners
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>
</shape>
<android:shape="rectangle" android:padding="10dp">
您是否可以通过从按钮属性中删除android:background=“@drawable/roundbutton”
进行检查。如果文本完全显示,那么您需要修改@drawable/roundbutton”
可能是您设置了固定宽度
,因此按钮中的文本不完全可见。您的按钮上似乎有一个paddingLeft
。您可以检查style.xml
中是否存在此项吗
如果它在你的styles.xml
中,那么它对于你应用的主题可能很重要
如果您只想在特定的按钮中取消它,只需将
android:paddingLeft="0dp"
试着替换
android:text=“@string/latestButtonString”
并将直接硬编码字符串放在这里
作为
或
尝试替换roundbutton.xml中的此行:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<!-- you can use any color you want I used here gray color-->
<solid android:color="#ABABAB"/>
<corners
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>
</shape>
<android:shape="rectangle" android:padding="10dp">
与
面临着类似的问题…以下属性使其正常工作:
android:layout_weight="1"
请删除以下行android:background=“@drawable/roundbutton”,但视图不能像您一样创建如果要创建相同的视图,请尝试以下代码:
代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<LinearLayout
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="40dp"
android:padding="20dp"
android:background="@drawable/roundbutton">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="latestButtonString"
android:textColor="#000000"
android:textSize="18sp"/>
</LinearLayout>
我遇到了这个问题,我通过将按钮的xml从“使用工具:”更改为“文本”属性的“android:”。下面的示例(最后一行是更改的行):
变成
<Button
android:id="@+id/btn_settings"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#F6F6F6"
android:text="App Settings" />
Add android:gravity=“center”在按钮中您可以发布您的xml代码……xml已添加,除了快照中显示的文本视图之外,没有其他可添加的内容。我尝试了gravity,但没有工作:(显示您的可绘制/圆形按钮xml文件…该文件中一定有问题…您在emulator中测试了吗!?我已经尝试过了,但没有显示文本。它仅在我更改布局时显示。\u width=“300dip“但不是以事件为中心的。这不是一个可接受的解决方案只是一个混乱,请检查@string/latestbuttonnstring
是否存在您想要查看的内容。您的圆形按钮
正常,请检查它。您是否检查了模拟输出,有时eclipse会由于某些故障而呈现错误。”。
<Button
android:id="@+id/btn_settings"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#F6F6F6"
android:text="App Settings" />