2

カスタム ビューを使用せずに、標準アクション バーのタイトルに複合ドローアブル (drawableLeft のようなもの) を追加することは可能ですか?

Atm タイトルに SpannableString を使用しています (カスタム書体を使用するため)。Compund ドローアブルを設定できない場合、SpannableString に追加できる ImageSpan を使用することは可能でしょうか?

どうも

4

2 に答える 2

1

ええ、絶対に。簡単な例を次に示します。

    final int abTitleId = getResources().getIdentifier("action_bar_title", "id", "android");
    final TextView abTitle = (TextView) findViewById(abTitleId);
    abTitle.setCompoundDrawablesWithIntrinsicBounds(R.drawable.your_icon, 0, 0, 0);
于 2014-04-02T09:16:04.940 に答える
0

アドニールの答えに感謝しますが、アンドロイドロリポップでは機能せず、彼の方法に従って解決策を見つけました。標準化されていませんが、うまく機能します。

ViewGroup actionViewGroup = (ViewGroup) findViewById(getResources().getIdentifier("action_bar", "id", "android"));
if (actionViewGroup != null && actionViewGroup.getChildCount() > 0) {
    View view = actionViewGroup.getChildAt(0);
    if (view instanceof TextView) {
        TextView tv = (TextView) view;
            tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_test, 0, 0, 0);
    }
}
于 2015-05-26T08:30:41.047 に答える