我使用以下样式来布局按钮:
<style name="Button.Web" parent="@android:style/TextAppearance.Small">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:singleLine">true</item>
<item name="android:autoLink">web</item>
</style>
按钮本身嵌套在一些 LinearLayouts
中,这些 LinearLayouts
包裹在 ExpandableListView
中:
<Button
android:id="@+id/button_web"
style="@style/Button.Web" />
在 BaseExpandableListAdapter
的子类中,我为按钮的每个实例动态设置文本:
Button buttonWeb = (Button) convertView.findViewById(R.id.button_web);
buttonWeb.setText("http://www.example.com/" + page);
当我展开 ExpandableListView
的项目时,会显示该按钮(请参阅“编号 2”和“编号 4”中的按钮)。但是上面没有呈现文本。在我触摸按钮的那一刻,文本出现(参见“数字 3”中的按钮)。
实验
- 我在尝试样式设置时注意到
android:singleLine
的组合和android:autoLink
产生所描述的行为。 - 我发现
android:singleLine
实际上已弃用为stated in the API documentation .因此,我测试了android:maxLines
按照此处的建议设置为1
。这会生成一个带有多行垂直滚动文本的按钮。
最佳答案
我知道这个问题有点老了,但我遇到过类似的问题。在我的例子中,除了 autoLink 属性外,我还必须在 xml 中设置“android:textColorLink”属性。 TextView 的行为相同。
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:autoLink="phone|email"
android:textColorLink="@color/yourDesiredLinkColor"/>
可能对您没有帮助,但希望对其他人有帮助:)
关于android - 使用 android :singleLine and android:autoLink 时按钮文本不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19389462/