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)
Related
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
I'm trying to incorporate Google's LeftNavBarLibrary into my application. When I load the nav bar I end up with a black bar across the top of the activity. The bar appears to be taking up the space a traditional actionbar would occupy.
Does anyone know where the bar is coming from or how to remove it.
Thanks.
My application theme is slightly customized. Based on the AppCompat theme due to requirements of the MediaRouteActionProvider
styles.xml
<resources>
<style name="AppTheme" parent="#style/Theme.AppCompat">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#drawable/ab_gradient</item>
</style>
</resources>
The activity pictured above has a custom theme defined in the manifest.
AndroidManifest.xml
<activity
android:name="my.app.namespace.CoreActivity"
android:theme="#android:style/Theme.Holo.NoActionBar.Fullscreen" >
</activity>
The applications minimum sdk version is 14. So it's not exclusively a Google TV app. I've only been able to test this bug on my Android 4.1 and 4.4 devices.
I deal with the action bar this way:
getActionBar().hide();
Try to put this in your main activity or the activity that is the parent and always present.
Don't bother about the theme in manifest, just set your theme with title bar and hide it through the code.
Hope this helps.
Take a look at: Hide the Status Bar on Android 4.0 and Lower
Notice that this is in the <application> tag. That might help you.
<application
...
android:theme="#android:style/Theme.Holo.NoActionBar.Fullscreen" >
...
</application>
or programmatically:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// If the Android version is lower than Jellybean, use this call to hide
// the status bar.
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
setContentView(R.layout.activity_main);
}
You can set android:windowActionBar style to false by setting custom theme.
Note: In this case getActionBar() will return null. If you remove the action bar using a theme, then the window will not allow the action bar at all.
Thanks for the answers guys. The real issue was actually that the LeftNavBar.java class was creating an artificial margin at the top of the screen. I'd have thought that a google published library would be better than that, but apparently not.
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.
I would like to use the default Android Theme.Light in one my activities.
However, when this particular theme is applied in my application Manifest file for the selected activity:
android:theme="#android:style/Theme.Light">
it hides the activity Action Bar.
What needs to be done in java or xml code to preserve the Action Bar, using this particular Light scheme ?
As an alternative, I have used the following default scheme:
android:theme="#android:style/Theme.DeviceDefault.Light">
That scheme does show the activity Action Bar correctly, however some of its objects are not displayed as preferred. In particular, my preference would be to display buttons and spinners as per Theme.Light, but preserve the other style formatting offered by the Theme.DeviceDefault.Light
I would greatly appreciate some tips on how to achieve the above scheme formatting preferences. (I am using SDK = 16).
Why not use "android:style/Theme.Holo.Light" ? is the same but has actionbar it was added in the newer apis
I think you should use Holo.Ligt theme. The old android Theme.Light is not even aware of action bar.
I have the same problem, I like Theme.light's controls, I resolved it like this:
1) define "Theme.Light.ActionBar" in project's styles :
<style name="Theme.Light.ActionBar" parent="#android:style/Theme.Light">
<item name="android:windowNoTitle">false</item>
<item name="android:windowActionBar">true</item>
</style>
2) in the manifest use it :
<activity
android:name="com.your.Activity"
android:theme="#style/Theme.Light.ActionBar" >
I hope that may help
I have developed an android app that mainly targets smartphones. However in tablet emulator I see that it works on android 3.x, too.
However there is one little problem. The user cannot open OptionsMenu when he clicks on the menu button. As you know on the smartphone a menu appears from the bottom. But on tablet nothing happens.
I have read this http://developer.android.com/guide/topics/ui/menus.html#options-menu but still cannot figure out how to manage this. My app has a custom action bar.
My code is quite straight forward. In main activity:
#Override
public boolean onCreateOptionsMenu(Menu men) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.layout.menu, men);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
//...
}
}
And the prefs activity:
public class MdPrefsActivity extends PreferenceActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getPreferenceManager().setSharedPreferencesName(
MdSharedPrefs.PREFS_NAME);
addPreferencesFromResource(R.xml.prefs);
}
}
MdSharedPrefs class just contains some getters and setters to retrieve/write the pref values.
Any ideas how I can show the OptionsMenu on tablet?
As the documentation said:
Items in the Options Menu are accessible in two distinct ways: the
MENU button or in the Action Bar (on devices running Android 3.0 or
higher).
[...]
On Android 3.0 and higher, items from the Options Menu is placed in
the Action Bar, which appears at the top of the activity in place of
the traditional title bar. By default all items from the Options Menu
are placed in the overflow menu, which the user can open by touching
the menu icon on the right side of the Action Bar. However, you can
place select menu items directly in the Action Bar as "action items,"
for instant access [...]
So for Android 3.0 or higher you can see only the menu items in the ActionBar.
It is also important to notice that:
Beginning with Android 3.0 (API level 11), the action bar is included
in all activities that use the Theme.Holo theme (or one of its
descendants), which is the default theme when either the
targetSdkVersion or minSdkVersion attribute is set to "11" or greater.
But be aware that the ActionBar is visible only if you don't have an application or activity theme that explicitly hides it like
android:theme="#android:style/Theme.Holo.NoActionBar"
On a tablet, no hardware button that can be used to load the menus, you need to create two folders in your res: the first call it values-11 and the second call it values-14. Inside these folders, put these styles (styles.xml) that will replace your default basetheme in the values folder whenever devices of higher version are used:
Res/values-11
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 11 theme customizations can go here. -->
</style>
Res/values-14
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>