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.
Related
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"
I need to use custom radio buttons with background image, and space them evenly horizontally, I can achieve the spacing but cannot position the background image in the center of each button. My layout is as below.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="58dp">
<RadioGroup
android:id="#+id/group_bottom_bar"
android:layout_width="match_parent"
android:layout_height="52dp"
android:orientation="horizontal">
<RadioButton
android:id="#+id/v4_btn_trip"
style="#style/BottomTabBarButtonStyle"
android:button="#drawable/v4_tabbar_radio_trip" />
<RadioButton
android:id="#+id/v4_btn_agenda"
style="#style/BottomTabBarButtonStyle"
android:button="#drawable/v4_tabbar_radio_agenda" />
<RadioButton
android:id="#+id/v4_btn_favorite"
style="#style/BottomTabBarButtonStyle"
android:button="#drawable/v4_tabbar_radio_favorite" />
<RadioButton
android:id="#+id/v4_btn_settings"
style="#style/BottomTabBarButtonStyle"
android:button="#drawable/v4_tabbar_radio_settings" />
</RadioGroup>
</RelativeLayout>
The style is per below:
<style name="BottomTabBarButtonStyle">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:layout_weight">1</item>
I already set the gravity to center_horizontal.
I tried to replace android:button with android:background but that just stretched the image.
One of the selector files (v4_tabbar_radio_trip)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/ic_bottom_tab_trip_active" android:state_checked="true" android:state_pressed="true" />
<item android:drawable="#drawable/ic_bottom_tab_trip_active" android:state_pressed="true" />
<item android:drawable="#drawable/ic_bottom_tab_trip_active" android:state_checked="true" />
<item android:drawable="#drawable/ic_bottom_tab_trip" />
</selector>
This is its current state.
Update: The expected output is that the background image (the two dots) is in the middle of the greyed area (which is the radio button), not aligned to the left. Similarly for other icons
You can try this layout xml.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="58dp" >
<RadioGroup
android:id="#+id/group_bottom_bar"
android:layout_width="match_parent"
android:layout_height="52dp"
android:orientation="horizontal" >
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<RadioButton
android:id="#+id/v4_btn_trip"
android:layout_gravity="center"
android:button="#drawable/v4_tabbar_radio_trip" />
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<RadioButton
android:id="#+id/v4_btn_agenda"
android:layout_gravity="center"
android:button="#drawable/v4_tabbar_radio_agenda" />
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<RadioButton
android:id="#+id/v4_btn_favorite"
android:layout_gravity="center"
android:button="#drawable/v4_tabbar_radio_favorite" />
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<RadioButton
android:id="#+id/v4_btn_settings"
android:layout_gravity="center"
android:button="#drawable/v4_tabbar_radio_settings" />
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</RadioGroup>
</LinearLayout>
I know this is not good way of handling the things but it can do a trick for you and it is feasible for all screens.
Try it. Hope this helps you.
try to write
style="#style/BottomTabBarButtonStyle"
after the
android:button="#drawable/v4_tabbar_radio_settings"
in layout xml file.
Try out this!!
<LinearLayout
android:id="#+id/ll_radio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:layout_marginBottom="5dp"
android:weightSum="2" >
<RadioGroup
android:id="#+id/radioGrouprecharge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radioPreapaid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/transparent"
android:button="#android:drawable/btn_radio" />
<RadioButton
android:id="#+id/radIoPostpaid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center_horizontal" />
</RadioGroup>
</LinearLayout>
You are centering your button, but the drawable is always left-aligned.
The solution appears to be create a new radio group. Here is an example.
I am having a problem with my selector, I have 3 ImageView's in a LinearLayout all having the same selector as background, I have implemented onTouchListeners for all 3 ImageView's, but the selector only works on the first ImageView but not on the others... can someone give me a hint what is wrong here?
Selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/theme_color_green_dark" android:state_pressed="true" />
<item android:drawable="#color/theme_color_green" />
</selector>
Layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment_captcha_actions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:orientation="horizontal"
android:weightSum="100">
<ImageView
android:id="#+id/fragment_captcha_action_stop"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="33"
android:background="#drawable/selector_captcha_actions"
android:clickable="true"
android:src="#drawable/ic_stop"
android:tint="#android:color/white" />
<ImageView
android:id="#+id/fragment_captcha_action_skip"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="34"
android:background="#drawable/selector_captcha_actions"
android:src="#android:drawable/ic_media_ff" />
<ImageView
android:id="#+id/fragment_captcha_action_submit"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="33"
android:background="#drawable/selector_captcha_actions"
android:src="#android:drawable/ic_media_play" />
found the problem myself...
android:clickable="true"
was only set on the first element therefore the selector worked only on the first element
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.
I have troubles making my RelativeLayout change background drawable on click. I made it clickable and focusable but this make nothing change. The background remains static to enables drawable. Thanks in advance.
<RelativeLayout
android:id="#+id/bttn_type_rl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:background="#drawable/day_bttn_bg_red"
android:clickable="true"
android:focusable="true"
android:paddingLeft="5dp"
android:paddingRight="5dp" >
<ImageView
android:id="#+id/bttn_type_iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:contentDescription="#string/app_name"
android:src="#drawable/relationship" />
<TextView
android:id="#+id/bttn_type_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/bttn_type_iv"
android:layout_centerHorizontal="true"
android:layout_marginTop="1dp"
android:text="#string/type_bttn_txt"
android:textSize="#dimen/data_fill_bttn_txt_size"
android:textStyle="bold" />
</RelativeLayout>
Here is the selector xml in drawable:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/bttn_red_p_bg" android:state_enabled="false" android:state_pressed="true"></item>
<item android:drawable="#drawable/bttn_red_a_bg" android:state_enabled="true"></item>
</selector>