android - 使用 android :singleLine and android:autoLink 时按钮文本不可见

标签 android expandablelistview textview android-xml android-button

我使用以下样式来布局按钮:

<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”中的按钮)。

ExpandableListView


实验

最佳答案

我知道这个问题有点老了,但我遇到过类似的问题。在我的例子中,除了 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/

相关文章:

android expandablelistview,仅在单击组指示器时展开 View ,如果单击组指示器以外的任何位置,则打开新 Activity

android - 在警告对话框中显示 TextView

安卓开发: How To Keep Text When Orientation Changes?

java - 保存 imageButton 可见性 [Android]

android - 运行桌面版 libgdx 示例 gdx-invaders 时出现 java.lang.NoClassDefFoundError

android - Onfling 和 OnTouch 不能一起工作

android - ImageView 和 TextView 左右对齐怎么办?

java - 安卓相机 : app passed NULL surface

java - Android 中独特的(基于设备的)salt

android - 创建一个可扩展的 RecyclerView