Change Chip Widget style programmatically not working – Android

You can’t use the constructor val chip = Chip(context, null, R.style.CustomChipChoice) because the 3rd parameter isn’t the style but the attribute in the theme as R.attr.chipStyle. The Chip hasn’t a constructor with 4 parameters as other components because it extends AppCompatCheckbox which does not support a 4 parameter constructor. However you can use something different. … Read more

Android material chip component crashing app. Unable to inflate xml

Update your app theme to inherit from one of these themes: Theme.MaterialComponents Theme.MaterialComponents.NoActionBar Theme.MaterialComponents.Light Theme.MaterialComponents.Light.NoActionBar Theme.MaterialComponents.Light.DarkActionBar For example: <style name=”AppTheme” parent=”Theme.MaterialComponents.Light.NoActionBar”> Note: Using a Material Components theme enables a custom view inflater Source: https://www.material.io/develop/android/docs/getting-started/

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

Toolbar overlapping below status bar

Use android:fitsSystemWindows=”true” in the root view of your layout (LinearLayout in your case). And android:fitsSystemWindows is an internal attribute to adjust view layout based on system windows such as the status bar. If true, adjusts the padding of this view to leave space for the system windows. Will only take effect if this view is … Read more

Material Design not styling alert dialogs

UPDATED ON Aug 2019 WITH The Material components for android library: With the new Material components for Android library you can use the new com.google.android.material.dialog.MaterialAlertDialogBuilder class, which extends from the existing androidx.appcompat.AlertDialog.Builder class and provides support for the latest Material Design specifications. Just use something like this: new MaterialAlertDialogBuilder(context) .setTitle(“Dialog”) .setMessage(“Lorem ipsum dolor ….”) .setPositiveButton(“Ok”, … Read more

Round corner for BottomSheetDialogFragment

Create a custom drawable rounded_dialog.xml: <?xml version=”1.0″ encoding=”utf-8″?> <shape xmlns:android=”http://schemas.android.com/apk/res/android” android:shape=”rectangle”> <solid android:color=”@android:color/white”/> <corners android:topLeftRadius=”16dp” android:topRightRadius=”16dp”/> </shape> Then override bottomSheetDialogTheme on styles.xml using the drawable as background: <style name=”AppTheme” parent=”Theme.AppCompat.Light.NoActionBar”> <item name=”bottomSheetDialogTheme”>@style/AppBottomSheetDialogTheme</item> </style> <style name=”AppBottomSheetDialogTheme” parent=”Theme.Design.Light.BottomSheetDialog”> <item name=”bottomSheetStyle”>@style/AppModalStyle</item> </style> <style name=”AppModalStyle” parent=”Widget.Design.BottomSheet.Modal”> <item name=”android:background”>@drawable/rounded_dialog</item> </style> This will change all the BottomSheetDialogs of your app.

How to set a gradient background in a Material Button from Material Components?

Starting with the version 1.2.0-alpha06 you can use the android:background attribute in the MaterialButton. <MaterialButton app:backgroundTint=”@null” android:background=”@drawable/button_gradient” … /> Otherwise if you can’t use the 1.2.0-alpha06 or higher you have to use the AppCompatButton component. Just a some tips about the MaterialButton. Currently the backgroundTint is still the default MaterialButton style. If you are using … Read more

Android button background is taking the primary color

Since you are using a Theme.MaterialComponents.* your Button is replaced at runtime by a MaterialButton. Currently the backgroundTint is still the default MaterialButton style. It means that if you are using a custom android:background, you have to make sure to null out backgroundTint to avoid that the custom background doesn’t get tinted with the attr/colorPrimary … Read more

Put constant text inside EditText which should be non-editable – Android

Did u try this method? final EditText edt = (EditText) findViewById(R.id.editText1); edt.setText(“http://”); Selection.setSelection(edt.getText(), edt.getText().length()); edt.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public … Read more