问题
I want to remove that 3 dots from toolbar and also want to add an image with textview on that position.That image and textviews are different for each fragment activity.
Also can anyone tell me how to make the toolbar transparent.
回答1:
In your MainActivity you will have optionmenu, just make it false
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return false;
}
回答2:
1)your First Question about removing three dots (Aditya -Vyas )solved your prob
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return false;
}
2) Now to put image view Crate Menu Resource
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_submit"
android:title="@string/submit"
android:icon="@drawable/ask_price_back"
app:showAsAction="always" />
</menu>
Then declare onCrateOptionsMenu and onOptionsImtemSelected as below
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_submit, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_submit) {
//Your code to handle click
return true;
}
return super.onOptionsItemSelected(item);
}
3) Handling The menu from the fragment loaded in activity try this
override this method in your fragment
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
getActivity().getMenuInflater().inflate(R.menu.menu_of_fragment, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_fragment) {
// Your code to handle Click
}
return super.onOptionsItemSelected(item);
}
回答3:
1) From your menu.xml remove all items with tag . This will remove three dots from your menu area.
2) Add a new item in your xml and give properties
android:icon="@drawable/image_you_want to show in the menu area"
app:showAsAction="always"
回答4:
set your style like
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionOverflowButtonStyle">@style/MyActionButtonOverflow</item>
</style>
<!-- Style to replace actionbar overflow icon. set item 'android:actionOverflowButtonStyle' in AppTheme -->
<style name="MyActionButtonOverflow" parent="android:style/Widget.Holo.Light.ActionButton.Overflow">
<item name="android:src">@drawable/ic_launcher</item>
</style>
check this post : post
回答5:
> for adding imageview and text
` <item android:id="@+id/action_cart"
android:icon="@drawable/cart2"
android:title="image"
app:showAsAction="always" />
<item
android:id="@+id/badge"
app:actionLayout="@layout/counter"
android:title="image"
android:icon="@drawable/shape"
app:showAsAction="always">
</item>`
In Layout counter
`<TextView
android:id="@+id/notif_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="20dp"
android:minHeight="20dp"
android:background="@drawable/shape"
android:text="0"
android:textSize="14sp"
android:textColor="#fff"
android:gravity="center"
android:padding="2dp"
android:singleLine="true">
</TextView>`
回答6:
Remove this item from menu.
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
visibility=false
android:title="@string/action_settings"/>
来源:https://stackoverflow.com/questions/44234410/how-to-remove-three-dots-from-the-toolbar-of-navigation-drawer