【发布时间】:2015-12-19 17:41:09
【问题描述】:
我一直在 Android 5.1.1 上开发应用程序,一切正常。但是当我在 4.0.4 设备上测试它时,没有一个按钮显示任何文本。知道为什么会这样吗?
每个按钮都是片段的 UI。这是布局,命名为just_a_button.xml:
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/button_copper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#fff"
android:visibility="gone"/>
这是片段如何设置视图的示例:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final Button button = (Button) inflater.inflate(R.layout.just_a_button, container, false);
button.setText(R.string.member_info);
// set click listener omitted
return button;
}
按钮的可见性由事件接收器控制。该按钮按预期显示,并且其单击侦听器有效。上面没有文字。
编辑:解决方案是将按钮放在布局中。我仍然很好奇这个要求是否被记录在案,为什么当按钮是根视图时似乎只有文本受到影响。
【问题讨论】:
-
为什么按钮文字是白色的??
-
@Clairvoyant 因为我使用的
@style很暗。 -
何时将可见性从已消失更改为可见?
-
@YonatanNir 在另一个片段完成 HTTP 请求之后。它在事件总线上广播从响应中解析的对象,每个按钮片段接收它并设置自己的可见性。按钮本身是可见的,而不是文本。
标签: android android-fragments android-button