Share button in ActionBar icon not default. How to change it? - java

I added share button to my ActionBar, but icon of that button seems not ok.
Default button looks like that:
https://monosnap.com/image/yiBpHo6XcMWKmXD1zwcy2w2gRkFBPN.png
But in my case it looks just like "SHARE" textin actionBar:
https://monosnap.com/image/d8cXbr5XIFtwItoaXAKkTjVBPr5eEa.png
How to change it to default?
Here is my menu xml file for activity:
<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="com.XXXXXXX.XXXXXXXXXXX.app.SomeActivity" >
<item
android:id="#+id/menu_item_share"
app:showAsAction="always"
android:title="Share"
android:actionProviderClass= "android.widget.ShareActionProvider" />
</menu>

add this
android:icon="#android:drawable/ic_menu_share"

<item
android:id="#+id/menu_item_share"
android:orderInCategory="100"
android:title="Share"
android:icon="#drawable/ic_launcher"
app:showAsAction="always"/>

Related

tools:showIn="navigation_view" not working

When i append tools:showIn="navigation_view" to my code it's not showing. But in video which i watched from Youtube this is working fine. What is the problem? Also I can't add library called
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_home"
android:icon="#drawable/ic_main_home"
android:title="#string/home" />
<item
android:id="#+id/nav_timetable"
android:icon="#drawable/ic_subject_timetable"
android:title="#string/timetable" />
<item
android:id="#+id/nav_ogrnot"
android:icon="#drawable/ic_ogrnot"
android:title="#string/ogrnot" />
<item
android:id="#+id/nav_yemek_menu"
android:icon="#drawable/ic_yemek_menu"
android:title="#string/yemek_menu" />
<item
android:id="#+id/nav_homework"
android:icon="#drawable/ic_homework"
android:title="#string/homework" />
</group>
<item android:title="#string/optional">
<menu>
<item
android:id="#+id/nav_to_do_list"
android:icon="#drawable/ic_to_do_list"
android:title="#string/to_do_list" />
<item
android:id="#+id/nav_logout"
android:icon="#drawable/ic_logout"
android:title="#string/logout" />
</menu>
</item>
</menu>
I had the same issue with my code. The first thing I did was to delete my already created menu file (Android resource file) and start the process from the top.
Secondly, after creating the menu resource file, on a new line, after typing (tool:), press alt+enter to add this automatically for you... xmlns:tools="http://schemas.android.com/tools"... Then you can go ahead to type in tools:showIn=".....".
To know if this works, in line of code in tools:showIn, when typing the name in the quotes, just type "na'... if there are other popups or suggestions, then you're good to go.
Hope this helps.

Bottom Navigation Bar not showing icons

I am initializing all of the icons with images but none of them are visible?
< ?xml version="1.0" encoding="utf-8"?>
< menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/nav_item1"
android:icon="#drawable/insta"
app:showAsAction="ifRoom|withText"
android:title="#string/nav1"/>
<item
android:id="#+id/nav_item2"
android:icon="#drawable/artistsample"
app:showAsAction="ifRoom|withText"
android:title="#string/nav2"/>
<item
android:id="#+id/nav_item3"
android:icon="#drawable/artistsample"
app:showAsAction="ifRoom|withText"
android:title="#string/nav3"/>
<item
android:id="#+id/nav_item4"
android:icon="#drawable/artistsample"
app:showAsAction="ifRoom|withText"
android:title="#string/nav4"/>
</menu>
Can you please use the bellow code and see what happens.
<item
android:id="#+id/nav_item2"
android:icon="#drawable/artistsample"
android:title="#string/nav2"/>
and enable app:labelVisibilityMode="labeled" in BottomNavigationView

Android - How to add a default checked CheckBox to Navigation Drawer

I want to add a check box to Navigation Drawer, and I want one of them to be default checked
I'm using this: app:actionViewClass="android.widget.Switch" as suggested in this answer.
But I couldn't figure out how to make one of them default checked. If I use this property android:checked="true", then the option is checked instead of checkbox (See image).
Does anyone know how to make it default checked (if possible, I want to do it in XML only)?
Here is my activity_drawer.xml.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:showIn="navigation_view">
<group
android:checkableBehavior="single">
<item
android:id="#+id/checkboxX-axis"
android:title="Show x-axis"
android:icon="#drawable/ic_x_axis_black_24dp"
app:actionViewClass="android.widget.CheckBox"
android:checked="true"
/>
<item
android:id="#+id/checkboxY-axis"
android:title="Show y-axis"
android:icon="#drawable/ic_y_axis_black_24dp"
app:actionViewClass="android.widget.CheckBox"
/>
<item
android:id="#+id/checkboxZ-axis"
android:title="Show z-axis"
android:icon="#drawable/ic_z_axis_black_24dp"
app:actionViewClass="android.widget.CheckBox"
/>
</group>
</menu>
You can do this:
MenuItem item = navigation.getMenu().findItem(R.id.checkboxX-axis);
CompoundButton compoundButton = (CompoundButton) item.getActionView();
compoundButton.setChecked(true);
replace navigation with the NavigationView's name.

Android: adding the camera icon to action bar on android studio

I am trying to an a camera icon to my action bar on android studio, but I can not see any icon. I can see is the "camera" text in my overflow. Below is my me.xml file which is in my menu folder, and also is below is my onCreateOptionsMenu() method
<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=".MainActivity">
<item android:id="#+id/action_logout"
android:title="#string/menu_logout_lable"
android:orderInCategory="100"
app:showAsAction="never"/>
<item android:id="#+id/action_edit_friends"
android:title="#string/menu_edit_friends_label" />
<item
android:id="#+id/action_camera"
android:title="#string/menu_camera_label"
android:icon="#drawable/ic_action_camera"
android:showAsAction="always" />
</menu>
i found out why, in my xml file, on the item for the camera
<item
android:id="#+id/action_camera"
android:title="#string/menu_camera_label"
android:icon="#drawable/ic_action_camera"
android:showAsAction="always"
/>
, i changed
android:showAsAction="always"
to
app:showAsAction="always"
the difference been changing android: to app: .
Thanks

How to expand android ActionBar?

How can i expand the actionbar like PlayNewsstand application and the image below :
What i am looking for found it here.
For your concern try using this in your manifest file ..
yourapp:showAsAction="ifRoom"
Ex:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
yourapp:showAsAction="ifRoom" />
...
</menu>
Complete reference :: http://developer.android.com/guide/topics/ui/actionbar.html

Categories