How to add a separator between menu items in ActionBar likewise it's made in Gmail app?
Well when I was trying to make my own action bar I used a black FrameLayout in which all the items of the action bar will be displayed. I set the layout_margin attribute on each item at 1dp so it would appear like there was a black separator on either side - if you want it to be larger you can increase the margin.
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000000">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton ....... />
<ImageButton ...... android:layout_marginLeft="1dp"/> <!-- this will be shown as a separator-->
</LinearLayout>
</FrameLayout>
Related
Hello guys i have a requirement where I need to move the action bar to little left and place a view on button click and again on button click i need to hide view beside action bar and make action bar to full width
I am using custom action bar in my activity
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getActionBar().setDisplayShowCustomEnabled(true);
getActionBar().setCustomView(R.layout.custom_actionbar_reader);
my custom view
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/menu_sidebar"
android:layout_gravity="center_vertical"
android:background="#android:color/transparent"
android:id="#+id/action_bar_back"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/search_reader"
android:id="#+id/action_search"
android:clickable="true"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:layout_centerVertical="true"/>
</RelativeLayout>
Is it possible to move action bar, I serched a lot but didnt find any thing related to it. Is that possible? if yes how?
Like the title says is there a way either via xml or programmatically to have a list fill the height of the nav drawer if the list does not contain enough items.
For example if I have a list of 4 items with background color black, and the 4 items only take up half the height of the drawer the rest of the drawer is grey and looks silly.
I have countered this by increasing padding on each item, but its kinda hacky I think. Plus I have to increase the padding quite a bit on higher density devices I want to support.
In the case of the posted code I have added 22dp of padding for an xxhdpi device.
Any tips are appreciated.
Thanks.
Drawer XML
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout2"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/drawer_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="#+id/left_drawer"
android:layout_width="300dp"
android:layout_height="fill_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/black"
android:dividerHeight="1dp"
android:background="#android:color/darker_gray"
android:footerDividersEnabled="false"/>
</android.support.v4.widget.DrawerLayout>
Drawer Items xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="22dp"
android:paddingBottom="22dp">
<ImageView
android:id="#+id/item_icon"
android:layout_width="50dp"
android:layout_height="49dp"
android:padding="10dp"/>
<TextView
android:id="#+id/item_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/item_icon"
android:background="?android:attr/activatedBackgroundIndicator"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:textColor="#fff"/>
</RelativeLayout>
Do you have a static number of items? If so, you can easily get the total height of the ListView and divide it by the amount of items. Then, you set the item height to each row.
If you have a dynamic number of items it's a little bit more tricky, because you have to determine a minimum height for a row in order to display all this content and only set the calculated row height if it's greater than the determined minimum.
I have three controls arranged vertically, List View, Menu Button and Hidden Menu.
List view will occupy the whole screen and menu button will be stick to the bottom of the screen. When we touch menu button, hidden menu will slide up and will occupy the almost half screen. Hidden menu will not cover the whole screen.
What layouts can I use and how to arrange?
Added Extra Info.
Below is my test xml layouts. If I send off-screen for my sub menu, the list data is not loaded, i think it's because it's not displayed on screen.
<RelativeLayout
android:id="#+id/content_layout"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/header_layout"
android:background="#ffffff" >
<ExpandableListView
android:id="#+id/listview_Category"
android:layout_width="match_parent"
android:layout_height="500dp"
android:divider="#E5E5E5"
android:dividerHeight="1dp"
android:background="#aaaaaa"
tools:listitem="#layout/list_item"
>
</ExpandableListView>
<ImageButton
android:id="#+id/imageButtonMenu"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_gravity="center_horizontal"
android:contentDescription="#string/app_name"
android:src="#drawable/menu_icon" />
<ListView
android:id="#+id/listview_Cat"
android:layout_width="match_parent"
android:layout_height="500dp"
android:layout_toEndOf="#+id/imageButtonMenu"
android:background="#777777"
android:divider="#ffffff"
android:dividerHeight="1dp"
android:translationY="500dp"
tools:listitem="#layout/category_list_item" >
</ListView>
</RelativeLayout>
You can use a Frame Layout in which the list view covers the whole layout and the menu button is bottom aligned and the menu has a fixed width and height...
but since it is a sliding menu you are looking for you can also use Navigation Drawer introduced in the latest version of android.
I need to create a custom action bar that will have some image buttons and on click they will drop down a menu list.
i have designed the action bar using a linear layout.
i have the controls attached in my main activity and and the click events handled, but i don't know how to create the drop down controls.
i want to position the the dropdown controls below the clicked button. how can i make all of this?
this is my code for the action bar
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:background="#drawable/actionbar_background"
android:layout_height="65dp">
<Button android:id="#+id/btntest"
android:layout_marginLeft="50dp"
android:text="Sup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button android:id="#+id/btntest1"
android:layout_marginLeft="100dp"
android:text="Company"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button android:id="#+id/btntest2"
android:layout_marginLeft="100dp"
android:text="Client"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
</FrameLayout>
you can do this with an action provider which can be used by ActionProvider class...
It replaces an action item with a customized layout, but it also takes control of all the item's behaviors.
besides taking the control of appearance of items it also handles default events for menu...
check the link for more information...
http://developer.android.com/guide/topics/ui/actionbar.html#ActionView
I want to have a common bottom bar in Android. If any of the button is clicked then it should open up the new activity with bottom bar still at the bottom. Is there any way to achieve this? I have tried having a superclass with 4 buttons at the bottom and then opening new activity on click event but I do not know why the bottom bar is not displayed and also is this is the proper approach?
The way I did this was to have a single Activity consisting of a ViewFlipper which occupied most of the window, and the button bar at the bottom. The child "activities" were simply children of the ViewFlipper. Worked fine.
EXAMPLE ADDED LATER:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<ViewFlipper
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<!-- Your pages go here, i.e.: -->
<include android:id="#+id/page1" layout="#layout/page1" />
<include android:id="#+id/page2" layout="#layout/page2" />
...
</ViewFlipper>
<!-- Your bottom bar -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
... buttons or whatever you want here ...
</LinearLayout>
</LinearLayout>