I have published an application and I see that some users keep getting errors when they are in the sign-up activity.
The error I'm getting is:
Fatal Exception: java.lang.RuntimeException
Unable to start activity ComponentInfo{com.xxx.yyy/com.xxx.yyy.SignUpActivity}: android.view.InflateException: Binary XML file line #137 in com.xxx.yyy:layout/activity_sign_up: Binary XML file line #137 in com.xxx.yyy:layout/activity_sign_up: Error inflating class CheckBox
When I go to layout/activity_sign_up to line 137 I got this:
<CheckBox
android:id="#+id/cb_showPass"
android:layout_width="32dp"
android:layout_height="32dp"
android:background="#drawable/cb_visible_styles"
android:button="#null"
android:scaleX="0.6"
android:scaleY="0.6"
app:layout_constraintBottom_toBottomOf="#+id/et_SignUpPassword"
app:layout_constraintEnd_toEndOf="#+id/et_SignUpPassword"
app:layout_constraintTop_toTopOf="#+id/et_SignUpPassword" />
Which is used to show the eye in the EditText:
The drawable/cb_visible_styles is:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/cb_show" android:state_checked="false" />
<item android:drawable="#drawable/cb_hide" android:state_checked="true" />
<item android:drawable="#drawable/cb_show" />
</selector>
Where cb_show/cb_hide are png files:
I can't figure out what causes the error.
Some places say it is because of Scaling, some say it is because of Density, Can't figure out why for many users it is fine but for a specific few it doesn't.
One time it appeared on Samsung S21, the other at Nexus 5X. One time on Android 10 and the other on Android 8.1.
Thank you
I think you do a lot of hassle google provides an easy way to apply show hide password check XML below
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/passwordLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:hint="#string/password"
android:textColorHint="#color/white"
app:endIconTint="#color/edit_text_icon_gray"
app:errorEnabled="true"
app:errorTextColor="#color/error_color"
app:hintTextColor="#color/white"
app:startIconDrawable="#drawable/ic_baseline_lock_24"
app:startIconTint="#color/edit_text_icon_gray"
fancy:endIconMode="password_toggle">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/edtPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:fontFamily="#font/regular_font"
android:inputType="textPassword"
android:padding="20dp"
android:textColor="#color/white"
android:textSize="13sp"
android:theme="#style/MyEditTextStyle2" />
</com.google.android.material.textfield.TextInputLayout>
Remove Third Item tag from drawable/cb_visible_styles. and try to run.
Before:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/cb_show" android:state_checked="false" />
<item android:drawable="#drawable/cb_hide" android:state_checked="true" />
<item android:drawable="#drawable/cb_show" />
</selector>
After:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/cb_show" android:state_checked="false" />
<item android:drawable="#drawable/cb_hide" android:state_checked="true" />
</selector>
Related
Example
Here's an example of what I'm asking about. I don't know the name of this gray circle that appears when I click, but I need to make it smaller. Please, help.
My BottomNavigationView:
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigationView"
app:menu="#menu/bottom_nav_menu"
app:itemTextColor="#color/bottom_nav_color"
app:itemIconTint="#color/bottom_nav_color"
android:outlineProvider="none"
app:labelVisibilityMode="labeled"
app:itemIconSize="40dp"
android:layout_width="match_parent"
android:layout_height="65dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
My bottom_nav_color.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="#color/black" />
<item android:state_checked="false" android:color="#color/black"/>
</selector>
I use bottomNavigation.
I wanna fill the icon with the color "not the outside of the icon" when selected.
How can I do that?
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="56dp"
android:paddingTop="2dp"
android:background="#FFFFFF"
android:theme="#style/BottomNavigationTextStyle"
app:labelVisibilityMode="labeled"
app:itemIconSize="24dp"
android:layout_alignParentBottom="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:menu="#menu/buttom_navigation_menu">
</com.google.android.material.bottomnavigation.BottomNavigationView>
Use the itemIconTint attribute:
<com.google.android.material.bottomnavigation.BottomNavigationView
app:itemIconTint="#color/my_selector"
..>
and define a selector like:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:alpha="1.0" android:color="..." android:state_checked="true"/>
<item android:alpha="0.6" android:color="..."/>
</selector>
Use custom made images as per your requirement. You would need to add 2 images one for the active state and for deactive state.
Create a selector home_icon_selector.xml for your icon
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/your_active_icon_here" android:state_selected="true" />
<item android:drawable="#drawable/your_active_icon_here" android:state_pressed="true" />
<item android:drawable="#drawable/your_active_icon_here" android:state_checked="true" />
<item android:drawable="#drawable/your_deactive_icon_here" />
</selector>
Update your menu buttom_navigation_menu to use the selector above
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/menu_home"
android:enabled="true"
android:icon="#drawable/home_icon_selector"
android:title="#string/tab_title_home"/>
</menu>
I'm using android material design drawer layout. Everything is working perfectly. But I'm fetching little bit problem with drawer layout item padding left in Android API lever <= 19.
It works well in Android API level >= 21. Look at the screenshot :
But in Android API level <= 19, drawer layout items don't take proper padding in the left side. Look at the screenshot:
My xml files as following:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"
style="#style/styleActivity">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer"
android:background="#drawable/graphics_drawer_bg"
app:itemTextColor="#color/white_light"
app:itemBackground="#drawable/graphics_item_bg"
app:itemIconTint="#color/white_light"
/>
</android.support.v4.widget.DrawerLayout>
activity_main_drawer.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group
android:id="#+id/nav_top"
android:checkableBehavior="single">
<item
android:id="#+id/nav_routine"
android:icon="#drawable/ic_access_time_accent_24dp"
android:title="Routines" />
<item
android:id="#+id/nav_class"
android:icon="#drawable/ic_book_accent_24dp"
android:title="Classes" />
<item
android:id="#+id/nav_exam"
android:icon="#drawable/ic_local_library_black_24dp"
android:title="Exams" />
<item
android:id="#+id/nav_event"
android:icon="#drawable/ic_date_range_black_24dp"
android:title="Events" />
<item
android:id="#+id/nav_statistics"
android:icon="#drawable/ic_insert_chart_black_24dp"
android:title="Statistics" />
</group>
<group
android:id="#+id/nav_bottom"
android:checkableBehavior="single">
<item
android:id="#+id/nav_settings"
android:icon="#drawable/ic_settings_black_24dp"
android:title="Settings" />
<item
android:id="#+id/nav_help"
android:icon="#drawable/ic_help_outline_black_24dp"
android:title="Help" />
</group>
</menu>
Thanks in advance.
Try adding padding in android.support.design.widget.NavigationView.
For example:
<android.support.design.widget.NavigationView
...
android:padding="10dp"
...
/>
As you mentioned in the comment that you want to add padding only in
devices having API <= 19. To do this, make two folders in res
directory.
values-v11 and values-v21
In these folders, add a file dimens.xml and in it add dimension for NavigationView.
In dimens.xml of values-v11:
<dimen name="padding_left">10dp</dimen>
In dimens.xml of values-v21:
No padding for API >= 21
<dimen name="padding_left">0dp</dimen>
And finally in NavigationView looks like this:
<android.support.design.widget.NavigationView
...
android:paddingLeft="#dimen/padding_left"
android:paddingStart="#dimen/padding_left"
...
/>
Update:
In material design, the margin and padding are predefined but you can override these values.
<dimen name="design_navigation_padding_top_default" tools:override="true">0dp</dimen>
<dimen name="design_navigation_separator_vertical_padding" tools:override="true">0dp</dimen>
<dimen name="design_navigation_padding_bottom" tools:override="true">0dp</dimen>
I found this here
Try this as item
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:padding="20dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#222"
android:text="bla bla bla" />
<group
android:checkableBehavior="single">
<item
android:id="#+id/ChatItem"
android:icon="#drawable/chat_icon"
android:title="#string/title_chat"/>
<item
android:id="#+id/ClipsItem"
android:icon="#drawable/clips_icon"
android:title="#string/title_clip"/>
<item
android:id="#+id/CretaeItem"
android:icon="#drawable/new_camera"
android:title="#string/title_create"/>
<item
android:id="#+id/dopeItem"
android:icon="#drawable/star_icon"
android:title="#string/tittle_dope"/>
<item
android:id="#+id/followersItem"
android:icon="#drawable/doppes"
android:title="#string/title_followers"/>
<item
android:id="#+id/callPeopleItem"
android:icon="#drawable/call"
android:title="#string/title_call_people"/>
<item
android:id="#+id/gifs"
android:icon="#drawable/gf"
android:title="GIFs"/>
<item
android:id="#+id/memes"
android:icon="#drawable/memos"
android:title="Memes"/>
<item
android:id="#+id/community"
android:icon="#drawable/comunity"
android:title="Community"/>
<item
android:id="#+id/findPeopleItem"
android:icon="#drawable/search_new"
android:title="#string/title_find_people"/>
<item
android:id="#+id/settingsItem"
android:icon="#drawable/setting_icon"
android:title="#string/settings"/>
<item
android:id="#+id/disclaimerItem"
android:icon="#drawable/disclamer_icon"
android:title="#string/title_disclaimer"/>
<item
android:id="#+id/logoutItem"
android:icon="#drawable/logout_icon"
android:title="#string/logout"/>
</group>
This worked for me
Just add this one line in dimen.xml file
<dimen tools:override="true" name="design_navigation_icon_padding">10dp</dimen>
this line override padding of navigation menu item.
In my app, I want to get survey answers from the user. So, I've decided put smiley images to act as a radio buttons. Is it possible on android?
For example, I will show smiley images when user touches the image and it will be activated like a radio button. At a time, they will be allowed to only choose one. If anyone could guide me, I would appreciate it.
Example :
Thanks in advance!
This question has been answered before Below is from #Benito-Bertoli
RadioButton - how to use a custom drawable?
Give your radiobutton a custom style:
<style name="MyRadioButtonStyle" parent="#android:style/Widget.CompoundButton.RadioButton">
<item name="android:button">#drawable/custom_btn_radio</item>
</style>
custom_btn_radio.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:state_window_focused="false"
android:drawable="#drawable/btn_radio_on" />
<item android:state_checked="false" android:state_window_focused="false"
android:drawable="#drawable/btn_radio_off" />
<item android:state_checked="true" android:state_pressed="true"
android:drawable="#drawable/btn_radio_on_pressed" />
<item android:state_checked="false" android:state_pressed="true"
android:drawable="#drawable/btn_radio_off_pressed" />
<item android:state_checked="true" android:state_focused="true"
android:drawable="#drawable/btn_radio_on_selected" />
<item android:state_checked="false" android:state_focused="true"
android:drawable="#drawable/btn_radio_off_selected" />
<item android:state_checked="false" android:drawable="#drawable/btn_radio_off" />
<item android:state_checked="true" android:drawable="#drawable/btn_radio_on" />
</selector>
Replace the drawables with your own.
Try like this
<RadioGroup
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content">
<RadioButton
android:button="#null"
android:background="#mipmap/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:button="#null"
android:background="#mipmap/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:button="#null"
android:background="#mipmap/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RadioGroup>
output:(margin and pading by yourself)
I might be a bit late. Use android:button"#btmImage link"
<RadioButton
android:id="#+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:button="#drawable/ic_launcher"
android:text="male"
android:textColor="#90999d" />
I think these 3rd party libraries will help you achieve this functionality.
SimpleRatingBar
SmileBar
They are pretty easy to use also.
Actually you just need to handle these two states, and it will work already.
<RadioButton
android:id="#+id/paragraphRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#drawable/btn_paragraph"
android:padding="14dp" />
btn_paragraph.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/ic_paragraph_selected" android:state_checked="true" />
<item android:drawable="#drawable/ic_paragraph" android:state_checked="false" />
</selector>
I have a listview settup using an custom array adapter the list appears fine I have used an gradient ans the background of each item which also appears but the code also states to change gradient on tapping which doesnot occur below are my xml's
main.xml
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dividerHeight="0.1dp"
android:listSelector="#drawable/list_selector"
/>
row_list.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="#+id/txtListText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="20dp"
android:textSize="35sp"
android:textColor="#545454"
android:background="#drawable/ogbg"
/>
</LinearLayout>
list_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Selector style for listrow -->
<item
android:state_selected="false"
android:state_pressed="false"
android:drawable="#drawable/ogbg" />
<item android:state_pressed="true"
android:drawable="#drawable/ogpress" />
<item android:state_selected="true"
android:state_pressed="false"
android:drawable="#drawable/ogpress" />
</selector>
ogbg.xml// normal background gradient
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#FFFAFAFA"
android:centerColor="#FFFFFFFF"
android:endColor="#FFFFFFFF"
android:angle="90"/>
</shape>
ogpress.xml//gradient to change on tapping
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#FF05c1ff"
android:endColor="#7F05c1ff"
android:angle="90"/>
</shape>
I had a similar problem in the past. Try to switch the order of your selector items, I don´t know why, but the behavior of a selector depends on the order of items. If this doesn´t work, try to deparate "selected" and "pressed". Do an extra item for every state.