Style SnackBar in theme app

With the Material Components Library you can globally change the snackbar style in your app theme: <style name=”AppTheme” parent=”Theme.MaterialComponents.*”> <!– Style to use for Snackbars in this theme. –> <item name=”snackbarStyle”>@style/Widget.MaterialComponents.Snackbar</item> <!– Style to use for action button within a Snackbar in this theme. –> <item name=”snackbarButtonStyle”>@style/Widget.MaterialComponents.Button.TextButton.Snackbar</item> <!– Style to use for message text within … Read more

Android – How to disable STATE_HALF_EXPANDED state of a bottom sheet

I am using material library version 1.1.0 and the BottomSheetBehavior class has this property skipCollapsed, if you set it to true the bottom sheet will skip the STATE_HALF_EXPANDED. Here is my code: class FilterBottomSheet : BottomSheetDialogFragment() { private lateinit var behavior: BottomSheetBehavior<View> override fun onStart() { super.onStart() behavior.state = BottomSheetBehavior.STATE_EXPANDED } override fun onCreateDialog(savedInstanceState: Bundle?): … Read more

MaterialCardView crashes with material:1.1.0

you can just keep it in your materialcardview itself also: <com.google.android.material.card.MaterialCardView android:layout_width=”match_parent” android:layout_height=”wrap_content” app:cardCornerRadius=”8dp” **** android:theme=”@style/Theme.MaterialComponents.Light” ***** app:cardElevation=”8dp”>

What’s the difference between the CardView from com.google.android.material and android.support.v7.widget

There are 3 versions: android.support.v7.widget.CardView: it is provided by the old support libraries and it is deprecated. androidx.cardview.widget.CardView it is the androidx version and it replaced the support libraries. To use it you have to add the dependency implementation ‘androidx.cardview:cardview:x.x.x’. com.google.android.material.card.MaterialCardView is provided by the Material Components Library. To use it you have to add … Read more

Can’t change background color on MaterialButton without change colorAccent

1st Solution You can use app:backgroundTint to change back ground color of MaterialButton <com.google.android.material.button.MaterialButton android:id=”@+id/bittrexJsonViewButton” android:layout_width=”0dp” android:layout_height=”@dimen/min_height” android:layout_marginStart=”@dimen/half_default_margin” android:layout_marginEnd=”@dimen/half_default_margin” app:backgroundTint=”@android:color/holo_orange_dark” android:text=”@string/json_view” app:layout_constraintBottom_toBottomOf=”@+id/binanceJsonViewButton” app:layout_constraintEnd_toEndOf=”parent” app:layout_constraintStart_toEndOf=”@+id/binanceJsonViewButton” app:layout_constraintTop_toTopOf=”@+id/binanceJsonViewButton” /> 2nd Solution MaterialButton uses colorPrimary as background when button is in active state and colorOnSurface when disabled. So, you can define it in your theme and apply it on … Read more

Issue: change border color or box stroke for unfocused TextInputLayout in android

If you want to set the color for the outline box in unfocused mode instead of the default black, you have to add this line in colors.xml file which will override the default color for the outline box. copy this line as it is. you can change color to what you want. <color name=”mtrl_textinput_default_box_stroke_color”>#fff</color> until … Read more

Set com.google.android.material.chip.Chip selected color

Just set an attribute app:chipBackgroundColor and pass a color state list to it: <android.support.design.chip.Chip android:id=”@+id/test” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:checkable=”true” android:clickable=”true” android:focusable=”true” app:chipBackgroundColor=”@color/bg_chip_state_list” app:chipText=”Test” /> bg_chip_state_list looks like this: <?xml version=”1.0″ encoding=”utf-8″?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:color=”@color/colorSecondaryLight” android:state_checked=”true” /> <item android:color=”@color/colorPrimaryDark” /> </selector> However I also had to set android:clickable to true to make this work

CardView with different corner radius

It requires the official MaterialCardView (which extends the androidx.cardview.widget.CardView) and at least the version 1.1.0 of the Material components library. Add to your layout the MaterialCardView: <com.google.android.material.card.MaterialCardView style=”@style/CustomCardViewStyle” …> </com.google.android.material.card.MaterialCardView> Define a custom style inheriting a material card style (for example Widget.MaterialComponents.CardView) and use the shapeAppearanceOverlay attribute: <style name=”CustomCardViewStyle” parent=”@style/Widget.MaterialComponents.CardView”> <item name=”shapeAppearanceOverlay”>@style/ShapeAppearanceOverlay_card_custom_corners</item> </style> <style name=”ShapeAppearanceOverlay_card_custom_corners” … Read more

Android Circular Determinate ProgressBar

I have written detailed example on Android circular progress bar here on my blog demonuts.com You can also fond full source code and explanation there. Here’s how I made circular progressbar with percentage inside circle in pure code without any library. first create a drawable file called circular.xml <?xml version=”1.0″ encoding=”utf-8″?> <layer-list xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:id=”@android:id/secondaryProgress”> … Read more

Android Chip Custom Height Or Padding – Chipgroup spacing

In the 1.1.0-alpha* versions extra spacing is added for the chip. After a lot of hit and trial I managed to remove that spacing using: app:chipMinTouchTargetSize=”0dp” Looking at the class file for Chip, it seems that it’s related to Android’s minimum touch target size, so consider that before changing this.