My Android App has min sdk and target sdk set to 10, when I run my app on Nexus 4 -Android Version 4.2.2, it shows a menu option button beside the system navigation.
I am not using menu options in my app and I dont want to show the user this useless menu option. How can I remove it ?
I have read about this on http://android-developers.blogspot.com.au/2012/01/say-goodbye-to-menu-button.html but I do not get a concrete solution.
Attached is the image :
I dont want to change the sdk version for my app. Is it possible to remove menu option without changing sdk version?
You simply have to modify your targetSdk to something above 10. For instance, if you use last SDK you should use targetSdk=16
The concrete solution is in the article:
Add theme to your application:
<application android:theme="#style/NoActionBar">
Then define this theme for pre-Honeycomb in res/values/themes.xml:
<resources>
<style name="NoActionBar" parent="#android:style/Theme">
<!-- Inherits the default theme for pre-HC (no action bar) -->
</style>
</resources>
and for Honeycomb and later:
<resources>
<style name="NoActionBar" parent="#android:style/Theme.Holo.NoActionBar">
<!-- Inherits the Holo theme with no action bar; no other styles needed. -->
</style>
</resources>
If you set your target SDK version to 11 and below, the android legacy menu button will appear. But just in case you want to keep that target SDK version, you can just delete the method onCreateOptionsMenu, this way you won't inflate any options.
Related
I want to customize text style Android menu item.
I put this to styles.xml
<item name="android:actionMenuTextAppearance">#style/my_custome_actionbar_menu_item</item>
It does not work, but when I remove "android:", it work properly
<item name="actionMenuTextAppearance">#style/my_custome_actionbar_menu_item </item>
Do you know What is different between having "android: " and not?
if you use api7-13,use actionMenuTextAppearance,and if your sdk api>17,use android:actionMenuTextAppearance,maybe the sdk you are using is lower than 17.
I figure out the reason about AppCompat
With new AppCompat-v7 (v21) ActionBar style's properties need to refer to the app namespace, that is without android: prefix.
So,for retro-compatibility, we should use actionBarStyle along with android:actionBarStyle:
I recently started Android programming, all is good and dandy, but I've came across a problem that I couldn't find an answer to, and I really diged hard for 4 days so far.
My app uses support action bar, and to be specific "android.support.v7.app.ActionBarActivity". Long story short, I couldn't handle most of the stuff applicable to an Action Bar to this support one.
My app uses this support action bar by default due to setting up my mini sdk version to 14.
I want to be able to build an action bar from scratch, and customize it, since the default action bar is not responsive to my customization in styles.xml, etc.
I don't mind using Holo theme library instead of AppCompat.
So the question here, how can use Action Bar instead of Support Action Bar?
How can I extend my java class to use that instead of the support one?
Because none of the online customizing solutions are applicable to the support action bar.
A bit foggy description so I apologize for that.
Create a new project, and select the minimum API level as 15. When you do this, the appcompat-v7 library will not be required for this project as it is for projects with minSdkversion < 15. In this project, the classes android.app.ActionBarActivity and android.app.ActionBar will be used by default, i.e. the native AOSP classes and not the ones from the support library.
The following will let you have an ActionBar with custom background color as you want it, on API level 8 and above.
STEP 1. In your res/values folder, define an XML file theme.xml and add the following to it:
<resources
xmlns:tools="http://schemas.android.com/tools">
<style name="DefaultActionBarTheme" parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle" tools:targetApi="11">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarSize" tools:targetApi="11">#dimen/action_bar_wrap_content</item>
<item name="actionBarSize">#dimen/action_bar_wrap_content</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="android:background" tools:targetApi="11">#color/actionbarbgcolor</item>
<item name="background">#color/actionbarbgcolor</item>
<item name="android:height" tools:targetApi="11">#dimen/action_bar_wrap_content</item>
<item name="height">#dimen/action_bar_wrap_content</item>
</style>
</resources>
In the same folder make another XML file colors.xml and add the following to it:
<resources>
<color
name="actionbarbgcolor">#00FF00
</color>
</resources>
and to the existing file dimens.xml, add the last line:
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<!-- Optional, in case you wish to increase the default width of the Action Bar. -->
<dimen name="action_bar_wrap_content">55dp</dimen>
</resources>
In place of #00FF00 above, use the hex color code for the background color you wish to use in your ActionBar.
NOTE: The above will work assuming you are using the appcompat-v7 library. If not, then you'll have to use one of the Holo.Light themes instead of AppCompat.Light, and there will be other changes as well.
STEP 2. In your manifest file, you must add:
android:theme="#style/DefaultActionBarTheme"
to every <activity declaration if that Activity has the ActionBar.
Try this. It will work.
Zygotelnit answer works but you have to omit the ["tools:targetApi="11"] from item declaration otherwise it will give you an error for some reason.
On the other hand, I've found a much shorter and easier but not so optimized solution.While searching through the actionBar class and playing around here is the answer:
In your activity.java, go down to
protected void onCreate(Bundle savedInstanceState)
Anywhere appropriate in that method, write the following code:
ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new
ColorDrawable(Color.parseColor("#D62D20")));
You replace the color code by any color code of your choosing. It's obviously a hex color code.
I want custome actionbar so i edited values-v14/style.xml
Here is what i change in xml file
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<item name="android:height">60dp</item>
</style>
this is my java code where i enabled drawer icon
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayShowTitleEnabled(true);
Now I run on 4.2 and Up device its fine But when i run 4.1 device it's show back icon not drawer icon any answer must be appreciated.
you can see drawer icon replaced with back
Hear is image of 4.4.4 Device you can check and please help me
In your style.xml
<style name="Theme.mytheme" parent="android:Theme.Holo">
<item name="android:homeAsUpIndicator">#drawable/your_icon</item>
</style>
add any icon you want. Icon mostly depends on Device API level.
Your ask is not clear, however... if i understand, you have an application that runs well on 4.2 devices showing drawer icon on left side (drawer menu navigation i suppose). The same application on 4.1 devices doesn't show drawer icon but back icon.
Be sure that your style.xml is correct.
Note that values-v11/style.xml is for API 11+
For API 14+ you must use values-v14/style.xml is for API 14+
You can try to add a new folder to your project values-v19/style.xml for API 19+ Android 4.4
Look in Android Official API Guides -> App Resources -> Style for more details.
And as last I give you two links resources:
To create ActionBars: http://jgilfelt.github.com/android-actionbarstylegenerator/
Useful tools can be found here: http://romannurik.github.io/AndroidAssetStudio/index.html
After updating my device's android version(lollipop), my app's logo is not displaying in lollipop version. and color of action bar has changed.
I am using following theme in my application
android:theme="#android:style/Theme.DeviceDefault.Light"
What would be the issue?
Umm.. that style is follows device's default style.
If you want same style for all devices, set style like this. android:theme="#android:style/Theme.Holo.Light"
Then you can see style with app logo like as before for all devices & versions.
Or if you want Material style. you might be using Toolbar.
http://developer.android.com/reference/android/widget/Toolbar.html
You have to do few changes:
parent="#style/Theme.AppCompat.Light" need to applied in your
style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light">
</style>
</resources>
And then goto
File->Import (android-sdk\extras\android\support\v7). Choose "appcompat"
then
Project-> properties->Android. Select tab library "Add" and choose "appCompat"
I am having an application which contains Menu options, but in some of Jelly Bean devices we don`t have the Menu soft key button so in that case how can I show those menu options?
Do I need to check sdk version, based on which I have to implement functionality?
and I am unable to use hasPermanentMenuKey() function in my app.
My app targets
android:minSdkVersion="9"
android:targetSdkVersion="17"
Can anyone give me any suggestions?
I think, you must have given android-9 specific theme in Android Manifest.
Example
android:theme="#android:style/Theme.Light"
1) Since Android 4.0 we have Action Bar, so many of the device running Android 4.0 and above will not have Hardware Menu.
2) All your Menu will be in action bar.
3) So, you need to specify different theme to Android v-14 and above, for you app to display Action bar with your menu.otherwise you will not get Action bar so as you Menu.
How To Do It
1) In values/styles.xml
<resources>
<style name="AppBaseTheme" parent="android:Theme.Light"></style>
<style name="AppTheme" parent="AppBaseTheme"> </style>
</resources>
2) In values-v14/styles.xml
<resources>
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar"></style>
</resources>
3) In AndroidManifest.xml
android:theme="#style/AppTheme"
use a lower minSDKVersion. Then in those set there will be a soft key for option menu too. for example
android:minSdkVersion="5"
Since the ActionBar was introduced in HoneyComb the menu you set using the onCreateOptionsMenu is displayed on the ActionBar of the activity.If you specify the android:showAsAction="never|withText" the item goes into the overflow menu...something which looks like three dots and is displayed with it's full text.
You can use the same API you use in pre HoneyComb:
boolean onCreateOptionsMenu(Menu menu)
boolean onOptionsItemSelected(MenuItem item)