I created a menu folder under res folder and, in that menu folder, I created a file called drawer_menu.xml. This is the text of that file:
<?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:layout_width="match_parent"
android:layout_height="wrap_content"
android:checkableBehavior="single">
<item
android:id="#+id/nav_profile"
android:icon="#drawable/ic_profile"
android:title="Message" />
<item
android:id="#+id/nav_my_events"
android:icon="#drawable/ic_my_events"
android:title="Chat" />
</group>
<item android:title="Communicate">
<menu>
<item
android:id="#+id/nav_settings"
android:icon="#drawable/ic_settings"
android:title="Share" />
<item
android:id="#+id/nav_logout"
android:icon="#drawable/ic_logout"
android:title="Send" />
</menu>
</item>
</menu>
But the design view is white and blank. No element shows up.Also I don't get to see AppThemes option which usually shows up in layout xml files.
I am using Android Studio Canary 3.2 and looks like that.
So maybe is a bug of your Android Studio version.
I believe there is a problem with the Android Studio Preview which didn't load properly and needs to be checked. If you're using the latest Android Studio, try reopening-refreshing preview by clicking on Preview (in the right side of the app).
If this didn't solve the issue, double clicking on the Preview in the right side of the app when using code editor should show the preview or errors but i think it will be fixed by doing that since I've had the same issue and after reopening it, there were a force refresh for the layout and it fixed the issue somehow.
Try changing support libraries version to more stable as 27.1.1
if you have 28 SDK version change to 28.0.0-alpha1
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1
Related
I'm trying to add Font Awesome library to my android project but i just can't. I was reading each google result about this topic.
My menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/buzon"
android:icon="#drawable/ic_buzon"
android:title="#string/buzon" />
<item
android:id="#+id/objetivos"
android:icon="#drawable/ic_objetivos"
android:title="#string/objetivos" />
<item
android:id="#+id/home_action"
android:icon="#drawable/ic_go_home"
android:title="#string/title_home" />
<item
android:id="#+id/encuesta"
android:icon="#drawable/ic_encuesta"
android:title="#string/encuesta" />
<item
android:id="#+id/cursos"
android:icon="#drawable/ic_cursos"
android:title="#string/cursos" />
</menu>
I'm want to use Font Awesome icons in my items menu instead default android icons.
For references, i was trying to follow this guide without success.
How to use Font Awesome icon in android application?
I have a toolbar
There is a overflow that displays options in menu
On click of menu item, How to achieve a ripple animation
menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menuEventsTodayId"
android:title="#string/menu_events_today" />
<item android:id="#+id/menuUpcomingEventsId"
android:title="#string/menu_upcoming_events" />
<item android:id="#+id/menuSignOutId"
android:title="#string/menu_sign_out" />
</menu>
I tried with:
<item android:id="#+id/menuEventsTodayId"
android:background="?attr/actionBarItemBackground"
android:title="#string/menu_events_today" />
Its not working, How to properly achieve it
Just add the background as ?attr/selectableItemBackground. It will automatically give ripple on Android 5+
You can use following for android version above lollipop:
android:foreground="?attr/selectableItemBackground"
for prelollipop devices, you can use following:
compile 'com.balysv:material-ripple:1.0.2'
You need to define a separate style for your toolbar in the 'values' folder then add the following items to it:
<item name="selectableItemBackground">?android:selectableItemBackground</item>
<item name="android:colorControlHighlight">#color/ripple_material_dark</item>
Note:- As you can check this Link. ?android:selectableItemBackground is only properties which makes this animation.
it seems that what ever i did i cant set the icons visible to the tool bar, i've tried to do researches on many platforms, but nothing helped.
here is the xml menu:
<?xml version="1.0" encoding="utf-8" ?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/event_ic"
android:icon="#mipmap/ic_event"
android:title="profile"
android:showAsAction="always"
/>
<item
android:id="#+id/details_menu"
android:title="details"
android:showAsAction="never"/>
</menu>
you can see that even if i set the android:showAsAction to always, i still get the event item in the pop up menu without the icon.
Previously, before using AppCompat, I was using SherlockActionBar to support Android 2.3.
The following menu works just perfect under SherlockActionBar
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/menu_browser"
android:title="#string/menu_browser"
android:showAsAction="ifRoom"
android:icon="?attr/actionBarBrowserIcon"/>
<item
android:id="#+id/menu_share"
android:title="#string/menu_share"
android:showAsAction="ifRoom"
android:icon="?attr/actionBarShareIcon"/>
</menu>
However, even since migrating to AppCompat, I realize the above menu doesn't work. I need to use app namespace, in order to make it work.
<?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/menu_browser"
android:title="#string/menu_browser"
app:showAsAction="ifRoom"
android:icon="?attr/actionBarBrowserIcon"/>
<item
android:id="#+id/menu_share"
android:title="#string/menu_share"
app:showAsAction="ifRoom"
android:icon="?attr/actionBarShareIcon"/>
</menu>
Why is this so? What is the difference comparing to SherlockActionBar, which makes app namespace unnecessary?
Attributes provided by libraries (or by the app itself) are suppose to be namespaced in order to avoid conflicts/collisions.
ActionBarSherlock masks this behavior by naming the attribute android:showAsAction. (As opposed to a showAsAction attribute in the android namespace): https://github.com/JakeWharton/ActionBarSherlock/blob/master/actionbarsherlock/res/values/abs__attrs.xml
my menu layout looks like this
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:blabla="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/msg_action_sections"
android:title="Sections view"
android:orderInCategory="100"
blabla:showAsAction="never" />
<item android:id="#+id/action_search"
android:title="Search"
blabla:showAsAction="collapseActionView"
blabla:actionViewClass="android.support.v7.widget.SearchView" />
</menu>
but eclipse keeps giving me this error : "Should use android:showAsAction when not using the appcompat
library"
I don't know how to tell Eclipse that I'm using it!!! In android studio it worked, but I can't use Android studio. So what should I do?
Thank you
PS: Im using support.v7.app.ActionBar and my Activity extends from ActionBarActivity
Ok I figured it out, problem is, that I had bad theme using in AndroidManifest. You have to use Theme which uses Appcompat as parrent:)