gpt4 book ai didi

java - 省略号禁用初始文本

转载 作者:行者123 更新时间:2023-12-01 15:12:43 25 4
gpt4 key购买 nike

singleLine=trueellipsize=start 与按钮一起使用时,我有一个奇怪的行为。

首先,我的按钮的声明:

<Button
android:id="@+id/enterDeparture"
android:layout_width="175dp"
android:layout_height="30dp"
android:layout_marginLeft="10dp"
android:background="@drawable/field_button"
android:text="@string/research_enterDeparture"
android:textColor="@drawable/field_button_textcolor"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:ellipsize="start"
android:singleLine="true" />

通过此声明,按钮内不会显示任何文本。但是如果我写 Log.d(TAG, "the text is : "+ findViewById(R.id.enterDeparture));,LogCat 就会给我正确的值...

我尝试在 onCreateView()onResume() 方法中以编程方式设置文本:行为相同。但是,如果我稍后设置文本,或者在屏幕上放置 AlertDialog,内容会立即返回...

最后,如果我删除两行 android:ellipsize="start"android:singleLine="true",一切都会正常:我的文本会显示在第一时间。

编辑

我尝试删除 singleLine=true 行:实际显示了初始内容,但椭圆行为不再起作用...

所以我尝试使用 maxLines=1 :显示初始内容,但“...”不再显示(内容只是被截断)。

最佳答案

尝试更改高度值:

android:layout_height="wrap_content"

您可能会将文本省略为...,并且因为填充文本的按钮可能被隐藏。

您也想尝试一下:

Log.d(TAG, "the text is : " + ((Button)findViewById(R.id.enterDeparture)).getText())

关于java - 省略号禁用初始文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12107954/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com