2

次のスタイルを使用してボタンをレイアウトします。

<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のようにラップされているものにネストされていExpandableListViewます。

<Button
    android:id="@+id/button_web"
    style="@style/Button.Web" />

IのサブクラスでBaseExpandableListAdapterは、ボタンの各インスタンスのテキストを動的に設定します。

Button buttonWeb = (Button) convertView.findViewById(R.id.button_web);
buttonWeb.setText("http://www.example.com/" + page);

ボタンの項目を展開するExpandableListViewと表示されます (「番号 2」と「番号 4」のボタンを参照)。ただし、レンダリングされたテキストはありません。ボタンに触れた瞬間にテキストが表示されます(「番号 3」のボタンを参照)。

ExpandableListView


実験

  • スタイル設定をいじってみると、 と の組み合わせが記述された動作android:singleLineを生成することに気付きました。android:autoLink
  • API documentation に記載されているように、android:singleLine実際には非推奨であることがわかりました。したがって、そこで提案されているように設定をテストしました。これにより、垂直方向にスクロールする複数行のテキストを含むボタンが作成されます。android:maxLines1
4

1 に答える 1

1

この質問はかなり古いことは知っていますが、同様の問題に直面しました。私の場合、xml の "android:textColorLink" 属性を autoLink 属性に追加して設定する必要がありました。動作は TextView と同じです。

<Button
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:autoLink="phone|email"
    android:textColorLink="@color/yourDesiredLinkColor"/>

おそらくそれはあなたを助けませんが、うまくいけば他の誰か:)

于 2016-11-16T15:03:16.967 に答える