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
Related
I'm working on an android app and am using a toolbar at the top of the screen and a navigation bar at the bottom of the screen. I'm using a single activity to create the top and bottom toolbars and fragments to change the content between the toolbars. However, when the contents in the fragment go beyond the size of the screen, the bottom bar disappears.
Here is my home activity xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_home"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.rentables.testcenter.HomeActivity">
<include
android:id="#+id/toolbar_main"
layout="#layout/toolbar_main"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<fragment android:name="com.rentables.testcenter.HomeFragment"
android:id="#+id/fragment_place"
android:layout_weight="0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="#layout/fragment_home" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="bottom">
<include
android:id="#+id/toolbar_navigate"
layout="#layout/toolbar_navigate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"/>
</LinearLayout>
</LinearLayout>
Im guessing it's because of the inner linear layout I have, but I wasn't sure how else to get the nav bar to stay static at the bottom. Any help would be awesome. Thanks
Figured it out. I just changed the whole thing to a relative layout, got rid of the inner linear layout, and instead of gravity I used alignParentBottom="true".
I am trying to hide the android action bar, I tried the following in the manifest:
android:theme="#android:style/Theme.NoTitleBar"
and also tried the following in my activity's onCreate method:
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();
setContentView(R.layout.viewpager);
Both work fine and the actionbar is invisible. But the problem is, I cannot use the space that the actionbar left after it disappeared. I mean, if I want to center a widget in the layout vertically, it counts for the space the action bar covers, and then centers the widget in the space left, and so it looks like not centered.Here is the xml file content:
<?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:background="#color/background"
android:gravity="center_vertical" >
<LinearLayout
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/imageview_create_db_first_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#drawable/data" />
<TextView
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal"
android:id="#+id/textview_create_database"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/create_database"
android:textSize="15sp"
android:textColor="#color/white_text"/>
</LinearLayout>
</RelativeLayout>
So can anyone help me with this?
Thanks
You should either use the no title flag:
requestWindowFeature(Window.FEATURE_NO_TITLE);
Or create your theme and add:
<item name="android:windowNoTitle">true</item>
Your code is fine. I have used similar code in my project. I think the margin:top attribute in your imageview is making it appear below the center.
android:layout_marginTop="20dp"
So remove this line.
I need a arc menu like above image but it is not scrolling. I need that i can add more menus and it should come from bottom while scrolling.And these menu will come after a tap on center button. Please help me.
I have a SemiCircularRadialMenu and there are individual fragments for every menu. I am opening fragments on clicking different menu but when I click on fragment, it also covers that SemiCircularRadialMenu. I want that when I click on the fragment, there should be no effect on SemiCircularRadialMenu.
My XML Code is given below (XML)
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<com.touchmenotapps.widget.radialmenu.semicircularmenu.SemiCircularRadialMenu
android:id="#+id/radial_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:padding="5dp" />
Code link for Semi Circular menu http://hasmukhbhadani.blogspot.in/2014/04/radial-menu-semi-circular-radial-menu.html (CIRCULAR OUTPUT SCREEN: is Semi Circular menu )
Can someone help me know how to place a Widget above a ActionBar in android.I have read some other similar queries on stackoverflow but it mentions its not possible.Following is the screen that i am trying to create.Can some one let me know how do i place the Blue layout portion above the actionbar?Or is there some other way of achieving this?
Following is my xml file
nearby.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:orientation="vertical"
android:background="#android:color/black"
>
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="100dp" >
</LinearLayout>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</android.support.v4.view.ViewPager>
</LinearLayout>
However i am not getting the desired layout.The header layout is visible below the actionbar.
Desired Layout:
The blue bar that you see is the action bar, using a custom view. Check out setCustomView on how you can customize the action bar.
Does anybody know how to easily implement an action bar with two stretched buttons?
Here is an example of the Google calendar app:
Thank you!
If you rather have this in the ActionBar for whatever reason, one way to achieve this is by using a custom view on the Action bar. Within you Custom View's layout then worry about setting up the buttons width.
Telling the activity to use a custom view for the action bar:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ActionBar ab = getActionBar();
ab.setDisplayShowHomeEnabled(false);
ab.setDisplayShowTitleEnabled(false);
final LayoutInflater inflater = (LayoutInflater)getSystemService("layout_inflater");
View view = inflater.inflate(R.layout.action_bar_edit_mode,null);
ab.setCustomView(view);
ab.setDisplayShowCustomEnabled(true);
}
layout/action_bar_edit_mode.xml can then look something like:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="fill_horizontal"
android:orientation="horizontal" >
<LinearLayout
android:layout_alignParentLeft="true"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:id="#+id/action_bar_button_cancel"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Cancel" />
<Button
android:id="#+id/action_bar_button_ok"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Ok" />
</LinearLayout>
</RelativeLayout>
Hope it helps someone!
Note: I realize the ugly nesting layouts here and normally I wouldn't recommend this but for some reason the actionbar's own layout refuses to let the LinearLayout take up the entire width on its own. Normally you should avoid nesting layouts unnecessarily like this!
Perhaps if someone sees this they can point us to a better solution?
What it looks like:
EDIT: There is an excellent post by Roman Nurik where he explains a way to do this very nicely.
EDIT 2: If anyone is curious, the correct way to lay out the buttons so that they expand the width of the actionbar without the need to nest your layouts like I did above, is to set the custom view with the proper layout parameters that allows its component to match the parent group.
Essentially:
actionBar.setCustomView(view,new ActionBar.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
I know 2 ways to do this, but one doesn't stay on top.
Here is the 1st:
You need to override the method onCreateOptionsMenu, but this is add on the ActionBar, you need API 11 to do this and when you rotate the screen this buttons appear on ActionBar, this depends of the screen size.
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
{
MenuItem add = menu.add(Menu.NONE, ADD_TIME, 0, R.string.add_time);
add.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
MenuItem qkAdd = menu.add(Menu.NONE, QUICK_ADD_TIME, 1, R.string.quick_add_time);
qkAdd.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
}
and this is the result:
if you're using a Fragment you need to set setHasOptionsMenu to true, otherwise the menu wont show.
Here is the 2nd:
cancel_done.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="#color/color_bar"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:dividerPadding="12dp"
android:orientation="vertical"
android:showDividers="end" >
<Button
android:id="#+id/button1"
style="#drawable/btn_cab_done_holo_light"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#drawable/btn_cab_done_holo_light"
android:text="CANCEL"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:dividerPadding="12dp"
android:orientation="vertical"
android:showDividers="beginning" >
<Button
android:id="#+id/button2"
style="#drawable/btn_cab_done_holo_light"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#drawable/btn_cab_done_holo_light"
android:text="DONE"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
the resource style btn_cab_done_holo_light.xml you can find on ..\sdk\platforms\android-%%\data\res\drawable and then on your layout you just add:
<include
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_gravity="fill"
layout="#layout/cancel_done" />
and this is the result:
I don't now if is the best way, but it's working.
Make a horizontal LinearLayout with two buttons. Then set each of their widths to match_parent and android:layout_weight="0.5"
(Each button will then take up 50% of the space).
EDIT:
To apply as the ActionBar background:
(ActionBarSherlock) getSupportActionBar().setCustomView(R.layout.my_view);
(ActionBar) getActionBar().setCustomView(R.layout.my_view);
You can use the actionMode of the ActionBar to implement the Done and Cancel actions.
See http://developer.android.com/guide/topics/ui/menus.html#CAB
Is called done bar in android. have a look at this it will be helpfull
https://github.com/googlesamples/android-DoneBar