I followed the instruction in http://developer.android.com/guide/topics/ui/actionbar.html
to make action bars. Basically, it works for one activity but not the other..
after change XML attribute to 'android' instead of what the developer sugguested 'yourapp' from xmlns:yourapp="http://schemas.android.com/apk/res-auto", it works for the one that failed initially
What is the problem here?
Following are the codes for each menu
This works for OutputPaymentActivity but NOT OutputRefinanceActivity
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:slc="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.simpleloancalculator.OutputPaymentActivity" >
<item
android:id="#+id/email"
slc:showAsAction="ifRoom|withText"
android:icon="#drawable/ic_action_email"
android:title="#string/email"/>
</menu>
vice versa:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.simpleloancalculator.OutputRefinanceActivity" >
<item
android:id="#+id/email"
android:icon="#drawable/ic_action_email"
android:title="#string/email"
android:showAsAction="ifRoom|withText"/>
</menu>
Thank you!
Try to replace with this :
xmlns:slc="http://schemas.android.com/apk/res/com.example.simpleloancalculator"
this value (com.example.simpleloancalculator) replace with your package name.
Related
I want to change navigation drawer icons, i am trying below code in Menu.xml file. But it showing only black icon.
<?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:context=".Welcome"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_kirtan"
android:icon="#drawable/point_red"
android:title="XYZ"/>
</group>
Expected output -
Please help me...!
Add below line in Activity class...
mNavigationView.setItemIconTintList(null);
Try to add color like this :
<item
android:id="#+id/nav_kirtan"
android:icon="#drawable/point_red"
android:title="XYZ"
android:tint="#color/redColor"
/>
or you can also do
mNavigationView.setItemIconTintList(null);
This disables all state based tinting.
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.
I would like to insert an image in the menu background, but in the properties of the menu is not such action. How I do this?
This is the menu code (it's very simple):
menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/MENU_1"
android:title="Gioca"/>
<item
android:id="#+id/MENU_2"
android:title="Esci"/>
</menu>
You need to add this in the xml:
android:icon="#drawable/your_icon_for_menu"
I had this menu xml that works fine:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:id="#+id/context_menu_save"
android:actionViewClass="my.app.TextViewPlus"
android:showAsAction="always"
android:title="#string/logout"
android:visible="false"/>
</menu>
But when i started using AppComap v7 i hade null exception when using getActionView().
I change my menu layout to:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res-auto" >
<item
android:id="#+id/context_menu_save"
myapp:actionViewClass="my.app.TextViewPlus"
myapp:showAsAction="always"
android:title="#string/logout"
android:visible="false"/>
</menu>
And now it works fine. Can anyone explain, why is it happens?
xmlns:myapp this is used when you create your own (or use others) customized views.
xmlns:android this is used when default android views.
so as ur question, i hope ur using your own (or use others) customized views. so u got error.
In Android Studio v1.5, I see the following message for this scenario:
When using the appcompat library, menu resources should refer to the app: namespace, not the android: namespace.
When not using the appcompat library, you should be using the android: namespace.
Im creating an android app which uses a menu.xml file in the res folder. But I'm getting the above error. What does it mean? How can I fix it?
menu.xml:
<?xml version="1.0" encoding= "utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item id="#+id/my_location"
android:icon="#drawable/my_location"
android:title:="Current location" />
<item id="#+id/mapview_satellite"
android:icon="#drawable/satelliteview"
android:title="Satellite View" />
<item id="#+id/mapview_normal"
android:icon="#drawable/normalview"
android:title="Normal view" />
</menu>
Change <item id="#+id/my_location" to <item android:id="#+id/my_location". This in all three places.
Also, in here: android:title:="Current location" remove the colon after title.
You also need to make sure the following two lines are in your attributes list:
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
If you omit those, Eclipse will just give you the "missing android prefix" error.
Believe it or not, for anyone who tries to work through examples in downloaded books, you may need to make sure you have true quotation marks as the compiler understands them. I'd been getting the same error as the OP, and many similar parse errors as I tried to modify an XML file in small ways. I noticed then that quote marks from the pasted code snippets were different from the ones on my keyboard (in the snippets they leaned to the right, and if I typed them myself they were straight up and down).
I know this sounds nuts and I could hardly believe it myself, but when I retyped my quotes it worked fine.
Adding android: before the attribute solved my problem.
create an XML file inside your project's res/menu/ directory Not in in res folder
&
dont forget to prefix the id attributes.
Try like this:
<?xml version="1.0" encoding= "utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/my_location"
android:icon="#drawable/my_location"
android:title="Current location" />
<item android:id="#+id/mapview_satellite"
android:icon="#drawable/satelliteview"
android:title="Satellite View" />
<item android:id="#+id/mapview_normal"
android:icon="#drawable/normalview"
android:title="Normal view" />
</menu>
Some times the XML code might be written correctly so you need to simply cut what you currently have and then delete it from the line numbers then re-paste it and the error should be fixed. If it doesn't then you know your code is wrong. The xml default is to recognize what you have put at first and needs to be removed in order to begin again. Trust me I just spent 3 days on that very problem and did exactly what is said above, good luck.
If you have something like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="person" type="com.abc.PersonEntity"/>
</data>
Move your data inside layout tag:
<layout xmlns:android="http://schemas.android.com/apk/res/android" >
<data>
<variable name="person" type="com.abc.PersonEntity"/>
</data>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
...
You've forgotten to prefix the id attributes. Try to do it like this:
<?xml version="1.0" encoding= "utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/my_location"
android:icon="#drawable/my_location"
android:title="Current location" />
<item android:id="#+id/mapview_satellite"
android:icon="#drawable/satelliteview"
android:title="Satellite View" />
<item android:id="#+id/mapview_normal"
android:icon="#drawable/normalview"
android:title="Normal view" />
</menu>
there was two error silly error
- id isn't it attribute is android:id
- First itme android:title:= you have written extra colon after title
here is implemented code
<?xml version="1.0" encoding= "utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/my_location"
android:icon="#drawable/my_location"
android:title="Current location"/>
<item
android:id="#+id/mapview_satellite"
android:icon="#drawable/satelliteview"
android:title="Satellite View"/>
<item
android:id="#+id/mapview_normal"
android:icon="#drawable/normalview"
android:title="Normal view"/>
</menu>