To create a navigation bar, I have dynamically create an action bar:
public void onCreate(Bundle savedInstanceState) {
ActionBar actionBar = getActionBar();
}
And add tabs one by one:
// Create first Tab
tab = actionBar.newTab().setTabListener(new FragmentsTab1());
// Create your own custom icon
tab.setIcon(R.drawable.tab1_hdpi);
actionBar.addTab(tab);
The problem is , the action bar is at the top by default. How can I placed it at the bottom? I found layout_below may be suitable for this case . However , as it generates dynamically, how can I know its ID? Thanks a lot.
Edited:
After adding split option, it doesn't make any changes, is it due to my action bar is dynamically generated?
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:uiOptions="splitActionBarWhenNarrow"
package="com.example.tabtest"
android:versionCode="1"
android:versionName="1.0" >
And
<activity
android:name="com.example.tabtest.MainActivity"
android:uiOptions="splitActionBarWhenNarrow"
android:label="#string/app_name" >
Add this to your activity tag in the Minifest
uiOptions="splitActionBarWhenNarrow"
You haven't really answered the OP's question.. I'm searching for an answer as well since it looks like the custom bar always gets placed top and default menu bar on bottom if I use this code to bring the custom view:
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowHomeEnabled(false);
// displaying custom ActionBar
View mActionBarView = getLayoutInflater().inflate(R.layout.custom,
null);
actionBar.setCustomView(mActionBarView);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
:(
With Android 5.0 API, uiOptions="splitActionBarWhenNarrow" is deprecated. Unfortunately, this is not very well documented as yet. For details, you can read up this article.
http://commonsware.com/blog/2014/11/18/android-5p0-deprecation-splitactionbarwhennarrow.html
Related
I'd like to hide the Action Bar of my Fragment.
I searched on Google for 1-2h. But I didn't find any proper anwser...
So if you could help me that would be nice.
You can try using getActivity().getActionBar().hide();
It is called ActionBar You can hide Action Bar using getSupportActionBar().hide();
I got a full screen activity that leads to an activity with an action bar. When the scond activity loads, the actionbar is half hidden by the title menu.
Why is this happening and what can I do to prevent it?
EDIT: as seen below, the title bar hides some of the action bar.
1 ) You have to keep same theme for all activity ,put actionbar activity them in application tag in manifest file
2) If you want to use full screen activity then getSupportActionBar().hide(); If you have Simle activity and Actionbar activity then while launching simple Actionbar activity to Simple activity creates problem.
check your activity deceleration in the manifest file. Declarer your activity like this.
<activity
android:name="com.android.MainActivity"
android:theme="#android:style/Theme.Light.NoTitleBar">
</activity>
I want to disable status bar in my application.
link
with:
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
I still can activate status bar with fast swipe from top to bottom screen.
Is possible to fully deactivate it?
What API version are you using? Anyway in the dedicated android developers page (Hiding the Status Bar) there is a detailed explanation on how to do it with additional clarification for API<16. In particular if the status bar should always remain hidden in your app you should set the activity theme in your app's manifest file as follows:
<application
...
android:theme="#android:style/Theme.Holo.NoActionBar.Fullscreen" >
...
</application>
I have a two level PreferenceScreen:
<PreferenceScreen>
general settings
<PreferenceScreen android:key="adv_settings">
more advanced settings
</PreferenceScreen>
</PreferenceScreen>
My problem is that the second screen doesn't show the back/up button on the action bar automatically. How do I make the up button appear on adv_settings?
You can add the arrow by writing a custom ActionBar style to be used with your application theme.
res/values-v11/styles.xml: (or add these to your existing styles.xml)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:displayOptions">showHome|homeAsUp|showTitle</item>
</style>
</resources>
Then apply this theme in your AndroidManifest.xml:
<application android:theme="#style/MyTheme">
Note: The obvious way to add this arrow should be to call:
getActionBar().setDisplayHomeAsUpEnabled(true);
once the second screen has loaded, but I think there's an Android bug where getActionBar() always returns the first-tier ActionBar object, as opposed to the one that is currently visible, so setting the arrow dynamically fails.
This may be more work, but you could create two PreferenceAtivity files each with their own PreferenceFragment. Each PreferenceFragment will have its own PreferenceScreen XML (the first level screen, and the second. level screen). From the firsts level screen you launch the second PreferenceActivity with an Intent within the tag. In the second PreferenceActivity you can set the home icon by doing this:
ActionBar bar = getActionBar();
bar.setDisplayHomeAsUpEnabled(true);
and then also had a handler for the home button:
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
if (item.getItemId() == android.R.id.home) {
finish();
}
return false;
}
Assets:
FirstPreferenceActivty
FirstPreferenceFragment
pref_first.xml (layout with PreferenceScreen and Prefernce nodes)
SecondPreferenceActivty
SecondPreferenceFragment
pref_second.xml (layout with PreferenceScreen and Prefernce nodes)
If the button does not come automatically, you could add it manually like done on these links:
Android: How can make custom PreferenceScreen?
http://pastebin.com/334Eip35
There is a example code in second answer of that SO question and the snippet in it is taken probably from the another pastebin location.
I've got an app that I've written targeting Android 2.1 which makes use of the menu button to expose some options. I'd like to have this menu available through the action bar overflow button in ICS, but I'm having trouble with getting it to show up.
If I change my target API to 15, the legacy menu button in the bottom bar disappears in ICS, but the icon in the top right of the action bar doesn't replace it, so there is no way to access the menu. I've tried adding the showAsAction attribute to the menu items, which did nothing. I'm definitely targeting 4.0.3 in my Eclipse build options.
All I want is for that menu to be accessible somewhere whilst using the ICS Holo theme, but still backwards compatible to older devices. How do I go about that?
Usually you add those Action Items simply by implementing the onCreateOptionsMenu(Menu menu) and adding the android:showAsAction="ifRoom" for the desired items in the menu's XML file.
e.g.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu_save"
android:icon="#drawable/ic_menu_save"
android:title="#string/menu_save"
android:showAsAction="ifRoom|withText" />
</menu>
Did you consider this fact?
Edit:
Here is a simple implemantation which worked for me a while ago:
#Override
public boolean onCreateOptionsMenu(Menu menu){
super.onCreateOptionsMenu(menu);
createMenu(menu);
return true;
}
private void createMenu(Menu menu){
MenuItem mnu1 = menu.add(0, 0, 0, "Logout");
{
mnu1.setAlphabeticShortcut('a');
mnu1.setIcon(R.drawable.icon);
mnu1.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
}
}
I was having this issue 5 minutes ago. Dont know if this can be still helpful, but this is how I got it solved:
Add super.setBooleanProperty("showTitle", true); to your onCreate method
#Override
public void onCreate(Bundle savedInstanceState) {
super.setBooleanProperty("showTitle", true);
super.onCreate(savedInstanceState);
//more code...
This will force the action bar to show and the menu button replacement will be there.
I am targeting android 4 in eclipse. Older devices show the bar as title only and of course are listening to default menu button action.