Button style in FragmentDialog - android

I've created a simple rating dialog, extending FragmentDialog. Below the result:
But I want obtain a style for the buttons like that one used in the typical dialog used in android
How can I obtain this result?

<View
android:id="#+id/divider"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_above="#+id/submit_layout"
android:layout_alignParentBottom="false"
android:background="?android:attr/listDivider" />
<LinearLayout
android:id="#+id/submit_layout"
style="#style/ButtonBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:descendantFocusability="beforeDescendants"
android:gravity="center_vertical"
android:minHeight="48dp"
android:orientation="vertical" >
<Button
android:id="#+id/reload_btn"
style="#style/ButtonBarButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/selectable_item_background"
android:minHeight="48dp"
android:text="Submit" />
</LinearLayout>
and "selectable_item_background.xml":
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/item_pressed" android:state_pressed="true" />
<item android:drawable="#drawable/item_focused" android:state_focused="true" />
<item android:drawable="#drawable/item_focused" android:state_selected="true" />
<item android:drawable="#android:color/transparent" />
</selector>

Supply STYLE_NO_FRAME to the method setStyle(int, int) of the DialogFragment and use TextViews instead of two buttons in your custom layout should do the trick.

Related

Remove custom toggle button text space android

Why is my toggle button taking the wrong width and have the space of text?
I want this toggle button to be exactly the same width as the other buttons
Here is the code:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#242424"
android:orientation="horizontal" >
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/ten_dp"
android:layout_weight="30"
android:background="#drawable/action_bar_btn_bg"
android:text="Close"
android:textColor="#color/abc_primary_text_material_dark" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="70"
android:gravity="right"
android:orientation="horizontal"
android:padding="#dimen/ten_dp" >
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/five_dp"
android:background="#drawable/action_bar_btn_bg"
android:button="#drawable/btn_fav"
android:gravity="center"
android:textOn="#null"
android:textOff="#null" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/five_dp"
android:background="#drawable/action_bar_btn_bg"
android:src="#drawable/ic_action_left" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/action_bar_btn_bg"
android:src="#drawable/ic_action_right" />
</LinearLayout>
</LinearLayout>
#drawable/action_bar_btn_bg
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/action_bar_btn_bg_pressed" android:state_enabled="true" android:state_pressed="true"/>
<item android:drawable="#drawable/action_bar_btn_bg_pressed" android:state_enabled="true" android:state_focused="true"/>
<item android:drawable="#drawable/action_bar_btn_bg_pressed" android:state_enabled="true" android:state_selected="true"/>
<item android:drawable="#drawable/action_bar_btn_bg_normal"/>
#drawable/btn_fav
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/ic_action_star_normal" android:state_checked="false" />
<item android:drawable="#drawable/ic_action_star_active" android:state_checked="true"/>
Please help me and tell me where I am going wrong?
Thank you.
Try adding a weight sum tag in the linear layout
android:weightSum = "3"
Then add weight attributes to the toggle and image buttons
android:weight="1"
EDIT: since you want to center the image within the toggleButton,
I recommend trying this in addition:
<ToggleButton
android:id="#+id/YourID
android:layout_width="0"
android:layout_height="75dp"
android:layout_weight="1"
android:checked="false"
android:textOn=""
android:textOff=""
android:drawableTop="#drawable/yourImage"
android:layout_gravity="center"
android:textColor="#yourColor"

Reduce Check box size in android?

i have tried out the suggestions given but unable to reduce the size...on reduction of size in graphical layout,the border lines of the checkbox disappear...iam new to android...any help will be appreciated
thanks
here is code...
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F3CAE5"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="8dp" >
<CheckBox
android:id="#+id/cb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/txt_id"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#000" />
<TextView
android:id="#+id/txt_fName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#000" />
</LinearLayout>
height and width change removes the border lines...check box appears in a list view that is populated dynamically...
the below code works for changing the checkbox image but now iam unable to check the box ie the tick mark does not appear on checking the box???
The text determines the size of the check box. try this:
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="new checkbox"
....... />
use custom image for check box
and use image of your size
<CheckBox
android:id="#+id/cb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#drawable/checkbox_selector" />
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:state_focused="true"
android:drawable="#drawable/checked" />
<item android:state_checked="false" android:state_focused="true"
android:drawable="#drawable/unchecked" />
<item android:state_checked="false"
android:drawable="#drawable/unchecked" />
<item android:state_checked="true"
android:drawable="#drawable/checked" />
</selector>

android : How to change background layout when focus and active

i have a problem when deploy my app, i want to change background layout color when focus and active, but when i run my aplication, there's nothing happen, this is my code :
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="visible" >
<LinearLayout
android:layout_width="600dp"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:layout_marginLeft="30dp"
android:focusable="true"
android:clickable="true"
android:background="#drawable/layout_state"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_margin="5dp"
android:layout_gravity="center"
android:background="#drawable/border_corner_baris2"
android:orientation="horizontal">
<TextView
style="#style/Textview_for_label"
android:layout_width="230dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Nama Lengkap \n(Sesuai KTP / Identitas Lain)" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:background="#drawable/border_corner_baris3"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_marginRight="10dp"
android:layout_gravity="center"
android:background="#drawable/border_corner_4"
android:orientation="horizontal" >
<EditText
android:id="#+id/nama_pp"
style="#style/edittext_border_corner_3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="20dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<ImageView style="#style/image_view" />
</LinearLayout>
and this is my layout_state :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_window_focused="false" android:state_enabled="true" android:drawable="#drawable/border_corner_baris1" />
<item android:state_window_focused="false" android:state_enabled="false" android:drawable="#drawable/border_corner_baris1" />
<item android:state_enabled="true" android:state_focused="true" android:drawable="#drawable/border_corner_baris1_klik" />
<item android:state_enabled="true" android:state_activated="true" android:drawable="#drawable/border_corner_baris1_klik" />
<item android:state_enabled="true" android:drawable="#drawable/border_corner_baris1" />
<item android:state_focused="true" android:drawable="#drawable/border_corner_baris1_klik" />
<item android:drawable="#drawable/border_corner_baris1" />
</selector>
is this possible to make this condition happen on my apps? i hope somebody can help me to solve my problem, thank you very much.
It wont work unless there is click listener present on the view(Linear Layout in your case). Either add
android:clickable="true"
in your linear layout, or add the OnClickListener to the linear layout in your activity.

change color of relative layout, and also its child elements

I have this relative layout:
<RelativeLayout
android:id="#+id/relativeLayout5"
android:layout_width="fill_parent"
android:layout_height="110dp"
android:layout_below="#+id/relativeLayout4"
android:background="#drawable/pigs_banner_selector"
android:clickable="true"
>
<ImageView
android:id="#+id/imageView9"
android:layout_width="220dp"
android:layout_height="60dp"
android:layout_marginTop="60dp"
android:layout_marginLeft="0dp"
android:layout_marginBottom="-10dp"
android:src="#drawable/banner_games_pighunt_hill" />
<TextView
android:id="#+id/textView3"
android:fontFamily="sans-serif-condensed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gluecksschweinjagd"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/white"
android:textSize="31sp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="6dp"
android:textStyle="bold" />
</RelativeLayout>
and the selector of the RelativeLayout:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_focused="true" android:drawable="#color/white"/>
<item android:state_pressed="true" android:drawable="#color/highlight_pigs_banner" />
<item android:drawable="#color/pigs_banner"/>
</selector>
The behavior is this: The relativeLayout changes it´s color as intended. But I want the Child elements (the ImageView) to also get the color of the selector (#color/highlight_pigs_banner).
EDIT:
The color highlight_pigs_banner basically puts alpha value on the color. How can I achieve this also on the imageview (child element) by still clicking only the RelativeLayout
I tried adding android:clickable="true" to the child elements, which didnt work, and android:addStatesFromChildren="true" to the relativeLayout which gave me an stackoverflow exception. Anyone knows how to achieve this? Thanks.
You should use Selector for ImageView and TextView as well.
<TextView android:id="#+id/textView3"
android:fontFamily="sans-serif-condensed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#drawable/text_selector" />
text_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="false"
android:state_pressed="false"
android:color="#color/normal"/>
<item android:state_pressed="true"
android:color="#drawable/highlight"/>
<item android:state_selected="true"
android:state_pressed="false"
android:color="#drawable/highlight"/>
</selector>
colors.xml
<drawable name="highlight">#ff590d</drawable>

Custom RadioButton image not filling space

I have a custom radiobutton with a 9-patch image as background. I use a Selector to determine the background.
I also have some text i want to put over the background of the image, but the text is aligning next to the button.
This is the RadioGroup
<LinearLayout
android:id="#+id/segmented"
android:layout_width="fill_parent"
android:layout_height="50sp"
android:gravity="center"
android:layout_below="#+id/header">
<RadioGroup android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/group1"
android:gravity="center">
<RadioButton
android:checked="false"
android:layout_width="90sp"
android:id="#+id/rbVerzekeringen"
android:text="Verzekeringen"
android:textSize="10sp"
android:button="#drawable/checkbox_theme" />
<RadioButton
android:checked="false"
android:layout_width="90sp"
android:id="#+id/rbPersoonlijk"
android:text="Persoonlijk"
android:textSize="10sp"
android:button="#drawable/checkbox_theme" />
<RadioButton
android:checked="false"
android:layout_width="90sp"
android:id="#+id/rbNotities"
android:text="Notities"
android:textSize="10sp"
android:button="#drawable/checkbox_theme" />
</RadioGroup>
</LinearLayout>
This is the Selector:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:state_window_focused="false"
android:drawable="#drawable/bt_filter_active" />
<item android:state_checked="false" android:state_window_focused="false"
android:drawable="#drawable/bt_filter" />
<item android:state_checked="true" android:state_pressed="true"
android:drawable="#drawable/bt_filter_active" />
<item android:state_checked="false" android:state_pressed="true"
android:drawable="#drawable/bt_filter" />
<item android:state_checked="true" android:state_focused="true"
android:drawable="#drawable/bt_filter_active" />
<item android:state_checked="false" android:state_focused="true"
android:drawable="#drawable/bt_filter" />
<item android:state_checked="false" android:drawable="#drawable/bt_filter" />
<item android:state_checked="true" android:drawable="#drawable/bt_filter_active" />
</selector>
And this is what it lookes like:
As you can figure out I want 3 large buttons with the text over it.
How can I do this?
EDIT:
I set the selector at background in stead of button and set the button to null.
The code looks like this now:
<LinearLayout
android:id="#+id/segmented"
android:layout_width="fill_parent"
android:layout_height="50sp"
android:gravity="center"
android:layout_below="#+id/header">
<RadioGroup android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/group1"
android:gravity="center">
<RadioButton
android:checked="false"
android:layout_width="100sp"
android:layout_height="40sp"
android:id="#+id/rbVerzekeringen"
android:text="Verzekeringen"
android:textSize="13sp"
android:orientation="vertical"
android:background="#drawable/checkbox_theme"
android:button="#null"
android:gravity="center"/>
<RadioButton
android:checked="false"
android:layout_width="100sp"
android:layout_height="35sp"
android:id="#+id/rbPersoonlijk"
android:text="Persoonlijk"
android:textSize="35sp"
android:background="#drawable/checkbox_theme"
android:button="#null"
android:gravity="center"/>
<RadioButton
android:checked="false"
android:layout_width="100sp"
android:layout_height="30sp"
android:id="#+id/rbNotities"
android:text="Notities"
android:textSize="13sp"
android:background="#drawable/checkbox_theme"
android:button="#null"
android:gravity="center"/>
</RadioGroup>
</LinearLayout>
But now when I make the buttons larger or smaller the text in it just disappears like this (height of the first image is 40sp, the second is 35sp and the last one is 30sp):
How can I make the background image smaller without cutting the text in it?
did you try setting the drawable as android:background instead of button?
see here.
EDIT:
I'm not sure but I think it depends on 9-patch content area (bottom and right edges lines), Android sets padding based on that if the 9-patch is set as background. The content area stretches with the image.

Categories

Resources