<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" tools:context=".activity.MemberActivity" > <item android:id="@+id/like_menu" android:title="" android:orderInCategory="60" app:showAsAction="always" app:actionLayout="@layout/view_content_like" /> <item android:id="@+id/comment_menu" android:title="" android:orderInCategory="60" app:showAsAction="always" app:actionLayout="@layout/view_content_reply" /> <item android:id="@+id/update_menu" android:orderInCategory="80" android:title="修改" app:showAsAction="never"/> <item android:id="@+id/delete_menu" android:orderInCategory="80" android:title="删除" app:showAsAction="never"/> </menu>
view_content_reply.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/name_textview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="@dimen/dp5" android:gravity="center" android:drawableLeft="@mipmap/reply_icon" android:drawablePadding="@dimen/dp3" android:text="57" android:textColor="@color/white" android:clickable="true" /></LinearLayout>
之后在optioonMenu中可以使用。
@Overridepublic boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.content_menu,menu); MenuItem item=menu.findItem(R.id.like_menu); TextView nameTextView= (TextView) item.getActionView().findViewById(R.id.name_textview); //좋아요 수량 nameTextView.setText("100"); MenuItem commentItem=menu.findItem(R.id.comment_menu); //댓글 수량 TextView commentNameTextView= (TextView) commentItem.getActionView().findViewById(R.id.name_textview); commentNameTextView.setText("500"); return super.onCreateOptionsMenu(menu);}
另外小提示:
toolbar的 menu中有drop图片。想对那个图片设置颜色则在style里使用 colorControlNormal
<?xml version="1.0" encoding="utf-8"?><resources> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> <item name="android:actionMenuTextColor">@color/white</item> <item name="actionMenuTextColor">@color/white</item> <item name="android:colorControlNormal">@color/white</item> </style></resources>
没有评论:
发表评论