-1
A
回答
0
考慮到功能,我相信你需要實現一些類似的佈局條件:
<?xml version="1.0" encoding="utf-8"?><android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/mainToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="?android:actionBarSize"
android:layout_marginRight="10dp"
android:gravity="right|center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/main_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
app:srcCompat="@drawable/heart_icon" />
<ImageView
android:layout_width="10dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="-20dp"
app:srcCompat="@drawable/number_icon" />
</LinearLayout>
0
okey然後你需要手動創建你的圖標菜單欄以對其進行完全控制。
首先在activity.xml
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/AppTheme.PopupOverlay" >
<!-- set any fixed size for 'width' but DO NOT set wrap_content-->
<RelativeLayout
android:layout_width="48dp"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/icon_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="[YOUR ICON]"/>
<!-- you can set any attributes you want (background-fixed position .. etc)
and you can also remove alignParentBottom , alignParentEnd ..
i just add it to be clear -->
<TextView
android:id="@+id/notification_text_view"
android:layout_width="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_height="wrap_content" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
那麼你可以,如果你使用的片段,然後做這些步驟直接訪問他們,如果你使用的活動..
在片段類:兩個IMAGE_ICON和text_notification
private ImageView iconImageView;
private TextView textNotificationView;
public void setIconImageView(ImageView iconImageView){
this.iconImageView= iconImageView;
}
public void setTextNotificationView(TextView textNotificationView){
this.textNotificationView= textNotificationView;
}
,那麼你需要手動設置片段添加二傳手。 在活動課
if(savedInstanceState == null) { // for rotation
[FragmentClass] fragment = new [FragmentClass]();
fragment.setIconImageView((ImageView)findViewById(R.id.child_list_search_edit_view))
fragment.setTextNotificationView((TextView)findViewById(notification_text_view))
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment, fragment, [Fragment TAG]).commit();
}else{
[FragmentClass] childActivityFragment =([FragmentClass]) getSupportFragmentManager()
.findFragmentByTag([Fragment TAG]);
fragment.setIconImageView((ImageView)findViewById(R.id.child_list_search_edit_view))
fragment.setTextNotificationView((TextView)findViewById(notification_text_view))
}
現在,只要你想,你可以添加您的通知。
+0
感謝我的問題,我已經嘗試過這個解決方案並且對我很好用 https://stackoverflow.com/questions/35009812/how-to-add-badges-on-toolbar-menuitem-icons?fref=gc –
相關問題
- 1. 菜單內的菜單項android
- 2. Android studio菜單項
- 3. Android菜單項onclick
- 4. Android選項菜單
- 5. Android菜單項目
- 6. Android選項菜單 - 單行中的一個菜單項
- 7. Android的 - 在一個菜單項
- 8. Android菜單項分離器(不同行中的菜單項)
- 9. 在Android的菜單onOptionsItemSelected造型菜單項
- 10. Android庫項目中的菜單項ID?
- 11. Android - 作爲選項卡的菜單項
- 12. Android的菜單項單分享按鈕
- 13. android選項菜單崩潰
- 14. Android StartActivity選項菜單
- 15. Android菜單項名稱
- 16. Android操作欄菜單項
- 17. 長按Android菜單項?
- 18. Android多選項菜單
- 19. 皮膚選項菜單Android
- 20. android菜單項描述
- 21. android-remove在右側選項菜單中刪除子菜單項的標題?
- 22. DropDownList的菜單:菜單項
- 23. 在菜單項上調用android上下文菜單按
- 24. 通過標題名稱在Android菜單中刪除菜單項
- 25. 在Android中看不到選項菜單
- 26. 在Android中創建選項菜單
- 27. 選項菜單不顯示在android
- 28. 在Android Studio中實現選項菜單
- 29. 在Android中添加選項菜單
- 30. Android項目不在菜單中出現
你有問題嗎? –
你有沒有嘗試或嘗試任何東西? –
有人給我這個鏈接 https://stackoverflow.com/questions/35009812/how-to-add-badges-on-toolbar-menuitem-icons?fref=gc 它解決所有 –