こんにちは私はTollbarを使用しています。内側にはメニューオプションでいくつかのドロウアブルアイテムを追加しました。私が望むのは、それらのドロアブルの中に数字を入れることです。通知数のあるTollbar
下の画像のように私は、ツールバーで、他のこれに関連記事はありませんが知っていると私は、ツールバーでする必要があります。
あなたはこんにちは私はTollbarを使用しています。内側にはメニューオプションでいくつかのドロウアブルアイテムを追加しました。私が望むのは、それらのドロアブルの中に数字を入れることです。通知数のあるTollbar
下の画像のように私は、ツールバーで、他のこれに関連記事はありませんが知っていると私は、ツールバーでする必要があります。
あなたは最も単純な方法は、スターバックグラウンドでのTextViewを使用することですありがとう:
<TextView
android:id="@+id/notification"
android:layout_width="@dimen/notification_width"
android:layout_height="@dimen/notification_height"
android:background="@drawable/bg_star"
android:gravity="center"
android:textColor="@android:color/white"
tools:text="5" />
設定または通知テキストを非表示にする明白なのTextViewののsetText()メソッドを使用することができます。
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<item
android:id="@+id/action_notifications"
app:actionLayout="@layout/view_notification"
app:showAsAction="always" />
</menu>
そして、このようなあなたの活動のinflateメニューで:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.notification_menu, menu);
return true;
}
okですが、これを使用してツールバーを追加しています。 ツールバーmiActionBar =(ツールバー)findViewById(R.id.miActionBar); setSupportActionBar(miActionBar); 動作しますか? –
はい。ツールバーにアクションを表示する場合は、メニュー項目を使用するのが正しい方法です。詳細については、[developer.android.com](https://developer.android.com/training/appbar/actions.html)をご覧ください。 – comrade
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_top"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="@color/action_bar_bkgnd"
app:theme="@style/ToolBarTheme" >
<TextView
android:background="@drawable/bg_star"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toolbar Title"
android:id="@+id/notification"
android:layout_gravity="center"
android:id="@+id/toolbar_title" />
</android.support.v7.widget.Toolbar>
Toolbar toolbarTop = (Toolbar) findViewById(R.id.toolbar_top);
TextView mTitle = (TextView) toolbarTop.findViewById(R.id.toolbar_title);
中のTextViewの背景用のXMLを作成するAndroidのメニューの
app:actionLayout
パラメータを使用し、あなたのツールバーにこのレイアウトを追加するにはツールバーので、カウンターのように表示されます私はあなたが見たいと思うそれをdemostrateすることができます –
確かに私を表示することはできますか?それ、どうやったら出来るの?私はツールバーに項目を追加できることを知っているので、私はTextViewを追加する方法を知らない –
@GerardoMendezDot私の答えの詳細をチェックしてください。カスタムレイアウトのメニューを追加するだけです。 – comrade