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

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

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

App menu option color

Hello I want to change my app menu option (black text on white Background instead of white text on black Backgroud )
Here is my menu xlm file
<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:context="com.androidsrc.tower.Liste1">
<item android:id="#+id/action_settings"
android:title="#string/action_settings" />
<item android:id="#+id/aide"
android:title="#string/aide" />
</menu>
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
Change your menu.xml to this:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
<item android:id="#+id/action_settings"
android:title="#string/action_settings" />
<item android:id="#+id/aide"
android:title="#string/aide" />
</menu>
In your styles.xml file add the following to your base app theme
<item name="android:popupMenuStyle">#style/CMOptionsMenu</item>
and then add the following styleto the file
<style name="CMOptionsMenu" parent="android:Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">#FFFFFF</item>
<item name="android:textColor">#000000</item>
</style>
In the AndroidManifest.xml remember to add the following to your application
android:theme="#style/AppBaseTheme"

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

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"/>

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