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
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?
I have a layout xml file:
<?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="match_parent"
android:orientation="vertical"
android:background="#000000" >
<FrameLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_above="#+id/taoFooter">
<com.example.gamedice.DrawingPanel
android:id="#+id/taoCanvas"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="#000000" />
</FrameLayout>
<LinearLayout
android:id="#+id/taoFooter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
style="#android:style/Holo.ButtonBar">
<Button
android:id="#+id/roll1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/roll1"
android:layout_weight="1"
style="#android:style/Widget.Holo.Button.Borderless"
android:onClick="rollTaoDice" />
<Button
android:id="#+id/roll2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/roll2"
android:layout_weight="1"
style="#android:style/Widget.Holo.Button.Borderless"
android:onClick="rollTaoDice" />
<Button
android:id="#+id/roll3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/roll3"
android:layout_weight="1"
style="#android:style/Widget.Holo.Button.Borderless"
android:onClick="rollTaoDice" />
<Button
android:id="#+id/roll4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/roll4"
android:layout_weight="1"
style="#android:style/Widget.Holo.Button.Borderless"
android:onClick="rollTaoDice" />
</LinearLayout>
</RelativeLayout>
In addition to other items in the layout, this layout has a button bar consisting of four buttons at the bottom of the screen. Based on user input, I want to be able to replace this button bar with another predefined set of buttons, and then be able to change back later.
Since I know what the alternate set of buttons will be ahead of time, I thought it might be possible to use an alternate layout xml file, but I couldn't figure out how to do that. Can anyone give me some guidance?
You can add your second set of buttons in a layout like you did with the first, then in the layout xml file set the attribute android:visibility="gone" on the second layout. In your code you can call setVisibility(View.GONE) for one layout (e.g. taoFooter) and setVisibility(View.VISIBLE) on the other layout when you need to switch the buttons out.
Alternatively, if you easily want to add some animations you can add a ViewFlipper around your two alternate button layouts. Only the first one is visible by default. You can switch to the next layout with showNext(). Add calls to setInAnimation() and setOutAnimation() before that to enable the animations.
I am making an application in which i am fetching data from JSON into ListView, but whenever i fetch more records into listview my bottom tab bar does not come it hides at that time, but if i have small number of records in listview like:- 3 or 4 item rows only, then i am able to see my records, when i was working with static listview at that point i was not getting the same problem because i was getting both large number of records with Fixed Bottom tab bar, so may i know what could be the problem?
There are following steps you can follow:
Use Relative layout.
Align bottom bar to the bottom as:
android:layout_alignParentBottom="true"
set list view above the Bottom bar as:
android:layout_above="#+id/bottomBarId"
It will work with Relative layout only.
Hope it will help.
see this, parent layout of list and bottom_bar should be
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/bottombar" >
</ListView>
<LinearLayout
android:id="#+id/bottombar"
android:layout_width="fill_parent"
android:layout_height="70dip"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:gravity="center" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bottom Tab bar"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</RelativeLayout>
Is it possible to show handle when drawer is closed and hide it when drawer is open ?
I've tried overriding SlidingDrawer but had no success so far.
To hide handle button following trick worked for me
<Button
android:id="#+id/handle"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#00000000" />
you can use slidingdrawer's topOffset attribute with a negative value in dp. (the size of your handle) like so:
android:topOffset="-50dp"
this way when you open the sliding drawer the handle will go pass the top screen making it gone from the view. now for a cleaner look you just have to create a transparent space between the handle and the content layout of your sliding drawer. you can do this by using a linearlayout with a transparent background assigned as your slidingdrawer's "android:content" layout and put your 'real' content layout inside and assigning a topMargin to it. looks something like this:
<LinearLayout
android:id="#+id/transparent_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/transparent" >
<LinearLayout
android:id="#+id/real_content_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp" >
</LinearLayout>
</LinearLayout>
and here's how the whole xml layout for your sliding drawer with "hiding" / "overshot" handle would look like:
<SlidingDrawer
android:id="#+id/slidingdrawer_no_handle_when_opened"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:content="#+id/hiding_handle"
android:handle="#+id/transparent_layout"
android:orientation="vertical"
android:topOffset="-50dp" >
<LinearLayout
android:id="#+id/hiding_handle"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/buttonTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hiding Handle" />
</LinearLayout>
<LinearLayout
android:id="#+id/transparent_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/transparent" >
<LinearLayout
android:id="#+id/real_content_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp" >
</LinearLayout>
</LinearLayout>
</SlidingDrawer>
*note - you need to adjust the value for topOffset and topMargin n accordance to you actual layout. and you need to provide another way for the user to close the sliding drawer since your handle is hidden when opened right? ;)
To hide the handle set the alpha to 0 and to show it set the alpha to 255.
handle.setAlpha(0); // hide
handle.setAlpha(255); // show
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>