I have searched a lot how to position ActionBarSherlock to the bottom of the screen and Thanks God it works using this code
<activity
android:name=".MyActivity"
android:uiOptions="splitActionBarWhenNarrow" >
</activity>
but with a small problem that the header is still there and I want to remove it also, so can any one please help me remove the header of ActionBarSherlock
Thanks in Advance
splitActionBarWhenNarrow means that it will be split, not moved anywhere and only when narrow. Thus if you are in portrait or wide screen the menu options will always appear at the top. You cannot force ActionBar to be drawn at the bottom. Instead you might want to disable ActionBar completely and putting your own custom view at the bottom with ImageButtons with actionButtonStyle
<style name="NoActionBar" parent="#android:style/Theme.Holo.Light">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/buttons_holder"
android:ellipsize="end"
style="#style/TextAppearance.Sherlock.Widget.ActionBar.Title"/>
<LinearLayout
android:id="#+id/buttons_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true" >
<ImageButton
android:id="#+id/acion_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/menu_label_add"
style="?attr/actionButtonStyle" />
<ImageButton
android:id="#+id/action_prev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/menu_label_prev"
style="?attr/actionButtonStyle" />
<ImageButton
android:id="#+id/action_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/menu_label_next"
style="?attr/actionButtonStyle" />
</LinearLayout>
</RelativeLayout>
Related
I have created custom tool bar in my android application.In my application,when I see layout is showing correct but when run application then show more margin from left side.I am extend AppCompatActivity in my Activity.
I have use following code for custom toolbar and XML
Code
ActionBar actionBar = getSupportActionBar();
// add the custom view to the action bar
actionBar.setCustomView(R.layout.custom_actionbar);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/nav_headerbg" >
<ImageButton
android:id="#+id/btnBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:background="#drawable/backbtn"
android:contentDescription="#string/clear" />
<ImageButton
android:id="#+id/btnHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/btnBack"
android:background="#drawable/ico_nav"
android:contentDescription="#string/clear" />
<TextView
android:id="#+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Setting"
android:textColor="#fff"
android:textSize="20sp" />
<ImageButton
android:id="#+id/btnDeviceList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="1dp"
android:padding="5dp"
android:background="#drawable/headerdevicelist"
android:contentDescription="#string/clear" />
</RelativeLayout>
Please find attached image.I want to remove left space which is marked by red.How to fixed it and suggest me.
Add custom actionbar style in your app:
<style name="MyActionBar" parent="Widget.AppCompat.ActionBar">
<item name="contentInsetStart">0dp</item>
<item name="contentInsetEnd">0dp</item>
</style>
and set it in your application theme:
<style (your application theme)>
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
Here is my layout.xml for splash screen.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#android:color/holo_orange_light"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="match_parent"
android:paddingBottom="#dimen/splash_padding_bottom"
android:paddingLeft="#dimen/splash_padding_left"
android:paddingRight="#dimen/splash_padding_right"
android:paddingTop="#dimen/splash_padding_top">
<LinearLayout
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:orientation="vertical"
android:layout_centerVertical="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/title"
android:textSize="#dimen/splash_title"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/app_name"
/>
<TextView
android:textColor="#android:color/white"
android:textSize="#dimen/splash_greetings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Hi\nthere,\ngood\nevening!"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
</LinearLayout>
</RelativeLayout>
and styles.xml (values-v21)
<resources>
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>
Now, when I ran the app on kitkat the splash screen was getting displayed properly but when I ran it on Lollipop all the padding I have given to RelativeLayout was gone.
What I am doing wrong?
This is the normal behavior, padding top and padding bottom are overwritten by the android:fitsSystemWindows="true".
You can find more by reading Ian Lake's Medium post on fitsSystemWindows:
https://medium.com/google-developers/why-would-i-want-to-fitssystemwindows-4e26d9ce1eec#.nljqv5yh8
Try adding android:margin instead
I need to use a custom View for my tabs, the problem is that fill_parent doesn't work (as seen here).
So I need to use margin and stuff, but in order to have the view centered inside the tab in all configuration (landscape/portrait, or on a tablet where the height of the tabs will change) it's a bit tricky to do.
I don't know what value to use on each configuration. Plus, I don't find the default layout that the system uses to start with.
I'd recommend that you use the ActionBar Tab styles. This is clean and simple. For example (zeroing in on the TabView):
<style name="MyActionBar" parent="#style/android:Widget.Holo.ActionBar">
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
<item name="android:attr/actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="android:attr/actionBarTabStyle">#style/MyActionBarTabStyle</item>
</style>
<!-- styling for the tabs -->
<style name="MyActionBarTabStyle" parent="#style/android:Widget.Holo.Light.ActionBar.TabView">
<item name="android:background">#drawable/tab_bar_bg_master</item>
<item name="android:gravity">center</item>
</style>
(I'll also note that the tabs are highly styleable by using custom Drawables. But that's a topic for another day!)
the above reply from #Stephane-Mathis is on the right track, but I couldn't get it to work just right in my code. Here's a simpler version that uses the same concept.
Again, the idea is to force your view to be much taller than the tab itself.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="3dp"
android:paddingBottom="3dp">
<View
android:id="#+id/spacer_1"
android:layout_width="0dp"
android:layout_height="1000dp"
android:layout_weight="1" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="#drawable/ic_tabicon_1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_gravity="center_vertical"
android:textColor="?accentColor"
android:text="My Albums" />
<View
android:id="#+id/spacer_2"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
The spacer_1 and spacer_2 views exist to pad the ImageView and TextView evenly on the left and right side. Furthermore, the height on spacer_1 is set to something absurdly high (1000dp) so force the parent view to be excessively tall. Then the ImageView and the TextView re both set to center_vertical.
So, if you want to do that you will need to do a bit of dirty stuff.
Since fill_parent doesn't work, you need to force the root view to have more height than the tab height and then center what you really need. So my first LinearLayout is useless, and the second one will be in the center of the tab.
Here is what I used. I just wanted one textview with another one at the top right of it.
<?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">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="invisible">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical">
<TextView
android:id="#+id/tv_tab_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/tv_tab_title"
android:layout_gravity="right"
android:background="#drawable/bg_notification"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:text="1"
android:gravity="center"
android:minWidth="14dp"
android:textStyle="bold"
android:textColor="#color/blanc"
android:textSize="8dp" />
<TextView
android:id="#+id/tv_tab_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="#color/noire"
android:textSize="12dp"
android:textStyle="bold" />
<TextView //this has the same height as the `tv_tab_count` so it remains centered vertically
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/tv_tab_title"
android:layout_gravity="right"
android:background="#0f0"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:text="1"
android:textSize="8dp"
android:visibility="invisible" />
</LinearLayout>
This work for the vertical alignment but the view only has the width of the content I put in my textview. So if you need to use the complete width, you should put a really really long word in one of the invisible textviews.
I have created a custom RatingBar as described in one of the tutorials given here on stack-overflow and it's looking great, the problem is with the centering of the image. here is what I've got:
As you can see the TextView is centered vertically in the LinearLayout, but the RatingBar is at the top of it. Here is my xml code of this image:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:foregroundGravity="center" >
<LinearLayout
android:layout_width="320dp"
android:layout_height="match_parent"
android:gravity="center" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<RatingBar
android:id="#+id/ratingBar1"
style="#style/starsRatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:numStars="5"
android:rating="2.3"
android:stepSize="1" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</ScrollView>
Here is the code of the styling:
<style name="starsRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/star_ratingbar_full</item>
<item name="android:minHeight">36dip</item>
<item name="android:maxHeight">36dip</item>
</style>
Any ideas in the RatingBar would be apprisiated!
THANKS
Ok, I think I've got it.
The key issue is the ScrollView: it automatically makes things compact, unless you specifically tell it otherwise. In the scroll view, set
android:fillViewport="true"
to make it use the space available.
Hello to get all items at top you have to put:
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:text="TextView" />
instead of:
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
if you just want the rating bar centred:
just remove style="#style/starsRatingBar"
EDIT:
forget any think I said befor, it seems to work better when I changed the style to : (adjust your min/max height to get "perfect result" )
<style name="starsRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#android:drawable/star_on</item>
<item name="android:minHeight">26dip</item>
<item name="android:maxHeight">26dip</item>
</style>
I am creating a custom dialog as:
Dialog myDialog = new Dialog(context, R.style.Theme_Levels);
myDialog.setContentView(R.layout.levelselector);
myDialog.show();
Style used:
<style name="Theme.Levels" parent="#android:style/Theme.Dialog">
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowBackground">#drawable/dlgbg</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
Layout xml file:
<LinearLayout android:id="#+id/LevelSelector"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_gravity="bottom|center_horizontal"
android:paddingBottom="50dip"
>
<Button android:text="Easy"
android:id="#+id/btn_Easy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
I want the button to appear at bottom center of the dialog (50dip padding from bottom) but it appears at top left of the Dialog.
Thats because LinearLayout does not know the width/height of the dialog, which is the size of the background image I have used in style xml file.
Question: How do I know the width height of the dialog so that LinearLayout is of the same size as the Dialog size?
Here is how you can do this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LevelSelector"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical"
android:paddingBottom="50dip" >
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<Button android:text="Easy"
android:id="#+id/btn_Easy"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Change android:layout_gravity="bottom|center_horizontal" to android:gravity="bottom|center_horizontal".
android:layout_gravity is gravity of the layout itself w.r.t. its parent. android:gravity applies to its contents.
i had the same problem in my case i ended up using a RelativeLayout
here it is.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/body" android:layout_margin="20dip"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="#drawable/dialog_bg"
>
<TextView android:id="#+id/message"
android:layout_alignParentTop="true"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_margin="10dip"
android:inputType="textMultiLine"
android:textColor="#color/table_text"
android:textScaleX=".95" android:textStyle="bold"
/>
<TextView android:id="#+id/dummy" android:layout_below="#id/message"
android:layout_width="fill_parent" android:layout_height="60dip"
android:visibility="invisible"
/>
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_margin="10dip" android:layout_below="#id/message"
android:layout_centerHorizontal="true" android:orientation="horizontal"
>
<ImageButton android:id="#+id/ok"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="#drawable/button_alert" android:src="#drawable/btn_yes"
android:visibility="gone" android:layout_weight=".5"
/>
<ImageButton android:id="#+id/cancel"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="#drawable/button_alert" android:src="#drawable/btn_no"
android:visibility="gone" android:layout_weight=".5"
/>
</LinearLayout>
</RelativeLayout>
Ok, I have found a way, not a clean way but works.
You need to add background in style.xml file
<item name="android:windowBackground">#drawable/levelselectbg</item>
AND also in you linearlayout:
android:background="#drawable/levelselectbg"
The first background is required to keep the dialog borderless (which I have specified in my style.xml in my question) and the linearlayout background is required to give size to the layout, now it knows its dimensions and places the button at bottom center with padding.
Hope this helps someone, if a better solution is available please share.