I just modified my action bar on my application to use the Split ActionBar functionality described here:
http://developer.android.com/guide/topics/ui/actionbar.html#SplitBar
I created a draft custom view in order to see the result on my device, here is the XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right" >
<ImageButton
android:id="#+id/action1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/actionButtonStyle"
android:src="#android:drawable/ic_menu_compass" />
<ImageButton
android:id="#+id/action2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/actionButtonStyle"
android:src="#android:drawable/ic_menu_compass" />
</LinearLayout>
In my Activity, I just modified my code to add the two required lines to set this custom XML and the way it should be displayed:
ActionBar actionBar = getActionBar();
actionBar.setCustomView(R.layout.action_bar_bottom); //load bottom menu
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME|ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.show();
The split is working well, my problem is that the action bar I was using previously is now at the bottom of the screen and the new one defined in the XML above is now displayed at the top of the screen, along with the Home button.
I looked at the function setDisplayOptions in the developer guide but it is not really clear for me how to use it.
Is there an easy way to invert the 2 action bars in order to let my main action bar at the top?
Thank you!
Related
I'm trying to style the action bar by adding a custom back button on the left and an icon in the center. The rendering in Android Studio is exactly as I want it, but when I test the layout on my phone, it just shows both back button and icon on the left, with the icon on top of the back button. This is my layout file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/action_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton android:id="#+id/back_button"
android:contentDescription="Image"
android:src="#drawable/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#color/action_bar_bg_color"
android:layout_alignParentLeft="true"/>
<ImageView android:id="#+id/cow_icon"
android:contentDescription="Image"
android:src="#drawable/cowhead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
And this is what I do to style the action bar:
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(false);
View mActionBar = getLayoutInflater().inflate(R.layout.action_bar_layout, null);
actionBar.setCustomView(mActionBar);
actionBar.setDisplayShowCustomEnabled(true);
Anyone see what could be causing the flawed styling of the action bar?
You could try using the new Toolbar : https://developer.android.com/reference/android/widget/Toolbar.html
which is great for making custom actionBar.
Otherwise, you don't have to make your back button custom, actionbar supports it with : https://developer.android.com/reference/android/app/ActionBar.html#setDisplayHomeAsUpEnabled(boolean)
I have created a custom action bar
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Choose"
android:textColor="#000000"
android:id="#+id/mytext"
android:textSize="18sp" />
</LinearLayout>
The java code
android.support.v7.app.ActionBar bar = getSupportActionBar();
bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
bar.setCustomView(R.layout.action_layout);
The screenshot
As you can see it leaves a mall black space to the top left of the screen. I don't want it. I want it to be pure white.
What needs to be done to achieve this.
Try to call setDisplayShowHomeEnabled() with false.
http://developer.android.com/reference/android/app/ActionBar.html#setDisplayShowHomeEnabled%28boolean%29
I am trying to create a popup on the actionbar item (like the one in G+ app).
To do this, I need to have the actionbar item view but this is available only setting a custom view with setActionView().
The problem is that I cannot reach the same menu item style of actionbar items.
I am using this:
<Button xmlns:android="http://schemas.android.com/apk/res/android"
style="?android:attr/actionButtonStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:background="#drawable/ic_refresh">
but the result is not good.
Where could I find a layout/style to mimic the action bar item one?
The solution is to use this layout:
<?xml version="1.0" encoding="utf-8"?>
<ImageButton xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#android:style/Widget.Holo.ActionButton"
android:src="#drawable/ic_refresh">
</ImageButton>
with the style #android:style/Widget.Holo.ActionButton
I have an ActionBar with a 3 menu items. The last one of these is a refresh button.
The refresh button sets the...
setProgressBarIndeterminateVisibility(true);
setProgressBarVisibility(true);
... to true, which shows the spinning progress icon on the ActionBar. Great!
But the trouble is it shows it in front of all the other icons. I want it to the right of all the icons, so I can hide the refresh button so it looks like it replaces the refresh button when the spinner is visible.
How I can accomplish this?
You'll need to make a custom ActionBar layout and position a Progress Bar (set to Indeterminate mode) wherever you want it. Then, instead of calling setProgressBarVisibility(true), just call ProgressBar.setVisibility() based on whether you need to show the spinner or not.
Here's an example of my app's custom ActionBar layout:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/app_name"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"/>
<ProgressBar
android:id="#+id/action_bar_progress_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:indeterminate="true"
android:layout_toStartOf="#id/search_view"
android:visibility="gone" />
<SearchView
android:id="#+id/search_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:title="#string/menu_search"
android:icon="#drawable/ic_search"
android:showAsAction="always"
android:actionViewClass="android.widget.SearchView"
android:layout_alignParentLeft="false"
android:queryHint="#string/menu_search_hint"
android:iconifiedByDefault="false"
android:layout_alignParentRight="true"/>
</RelativeLayout>
Just tweak the position of the ProgressBar until it's where you want it. Then, in your Activity's onCreate() set the layout:
ActionBar actionBar = getActionBar();
actionBar.setCustomView(R.layout.activity_start_screen_actionbar);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
am new to android apps am making an app Which has NFc technology,here i want to make a Notification bar like default OS statusbar Notification.
i made it custom now i want it to be call/display in all Screen while end user pull it from top to bottom within the app.
this is my custom Sliding drawer class and am using it in Main.xml file
<com.abc.xyx.customnotification.CustomDrawer
xmlns:my="http://schemas.android.com/apk/res/com.abc.xyx.app"
android:id="#+id/drawer"
my:direction="topToBottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
my:handle="#+id/handle"
my:content="#+id/content"
android:layout_marginTop="100dp"
>
<include
android:id="#id/content"
layout="#layout/slider"/>
<ImageView
android:id="#id/handle"
android:layout_width="wrap_content"
android:layout_height="150px"
android:visibility="invisible"
android:src="#drawable/tooltiparea" />
</com.abc.xyx.customnotification.CustomDrawer>
You should google it up, there are quite a few samples with good explanation, like these:
Android SlidingDrawer with Custom View or
Example to implement
SlidingDrawer in XML or
Widget: SlidingDrawer top to bottom
you should use oops for that
first make a BaseActivity which extends android.app.Activity. Now this will be the parent Activity for all of your app's Activities where you want to display status bar. Define all the function related to custom status bar in that and a parent layout for holding views related to child Ativity
xml layout for BaseActivity will be like this
<com.abc.xyx.customnotification.CustomDrawer
xmlns:my="http://schemas.android.com/apk/res/com.abc.xyx.app"
android:id="#+id/drawer"
my:direction="topToBottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
my:handle="#+id/handle"
my:content="#+id/content"
android:layout_marginTop="100dp"
>
<include
android:id="#id/content"
layout="#layout/slider"/>
<ImageView
android:id="#id/handle"
android:layout_width="wrap_content"
android:layout_height="150px"
android:visibility="invisible"
android:src="#drawable/tooltiparea" />
</com.abc.xyx.customnotification.CustomDrawer>
<RelativeLayout >
this layout is used for holding child Activities views
</RelativeLayout>
generate accesser method to access the slidingdrawer and parentLayout.
now your activities in which you want to add customSlidingBar should extends from BaseActivity in this way you only have to code once for sliding drawer implemation
hope it helps