Using extended floating action button with Appcompat theme - android

Is there a way to use the extended floating action button when your parent style is set to "Theme.AppCompat.Light.NoActionBar"?
I have the following in my layout. The app crashes because of style issue when my parent style is set to AppCompat.
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="#+id/viewMore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="16dp"
android:text="View More"
android:textColor="#color/colorPrimary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>

As suggested here, you could use a Material bridge theme to retain the AppCompat style.
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>

Related

Style not getting applied to material CheckBox in Android

I am trying to apply custom theme to remove extra space around checkbox using style.
But my style is note getting applied.
<com.google.android.material.checkbox.MaterialCheckBox
android:id="#+id/checkbox"
style="#style/TestCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintEnd_toStartOf="#id/title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" />
<!-- Style -->
<style name="TestCheckBox" parent="Widget.MaterialComponents.CompoundButton.CheckBox">
<item name="minWidth">0dp</item>
<item name="minHeight">0dp</item>
</style>
Not sure what is going wrong
This style add on your app theme
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<!-- .... -->
<item name="checkboxStyle">#style/TestCheckBox</item>
</style>

MaterialButton style being overridden, how do I keep it?

I'm trying to use a MaterialButtonToggleGroup inside my BottomSheetDialog. However the style for the button is being overriden by the current theme I'm using for the BottomSheet
In a regular fragment:
Using the attribute
style="?attr/materialButtonOutlinedStyle"
I have this blue outline on my Material Button inside my ToggleGroup
<com.google.android.material.button.MaterialButtonToggleGroup
android:id="#+id/toggle_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:checkedButton="#+id/btnOne"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="16dp"
app:selectionRequired="true"
app:singleSelection="true">
<com.google.android.material.button.MaterialButton
android:id="#+id/btnOne"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"
android:minHeight="0dp"
android:textSize="12sp"/>
<com.google.android.material.button.MaterialButton
android:id="#+id/btnTwo"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="0dp"
android:text="Button 2"
android:textSize="12sp"/>
</com.google.android.material.button.MaterialButtonToggleGroup>
But when using it inside my BottomSheet I get this:
The theme for bottom sheet I'm using:
<style name="Theme.TestApp" parent="Theme.MaterialComponents.DayNight.NoActionBar">
...
<item name="bottomSheetDialogTheme">#style/AppBottomSheetDialogTheme</item>
</style>
<style name="AppBottomSheetDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
<item name="bottomSheetStyle">#style/BottomSheetRoundedCorners</item>
</style>
<style name="BottomSheetRoundedCorners" parent="Widget.Design.BottomSheet.Modal">
<item name="android:background">#drawable/bgr_bottomsheet_round_corners</item>
</style>
How can I keep the style
style="?attr/materialButtonOutlinedStyle"
for the MaterialButton while using the BottomSheet's theme?
Edit:______________________________
I've tried adding
<item name="materialButtonStyle">#style/Widget.MaterialComponents.Button.OutlinedButton</item> to my BottomSheet's theme but it doesn't do anything.
<style name="AppBottomSheetDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
<item name="bottomSheetStyle">#style/BottomSheetRoundedCorners</item>
<item name="materialButtonStyle">#style/Widget.MaterialComponents.Button.OutlinedButton</item>
</style>
Have also tried it with
<item name="materialButtonStyle">?attr/materialButtonOutlinedStyle</item>
you can use this theme:
<style name="BottomSheet" parent="Theme.MaterialComponents.DayNight.BottomSheetDialog"/>
<style name="Theme.TestApp" parent="Theme.MaterialComponents.DayNight.NoActionBar">
...
<item name="bottomSheetDialogTheme">#style/BottomSheet</item>
DO NOT USE THEME.DESIGN.LIGHT

App crashing on applying style to TextInputLayout

I am getting below error when I am using style in TextInputLayout. How can I fix this?
Caused by: java.lang.IllegalArgumentException: The style on this
component requires your app theme to be Theme.MaterialComponents (or a
descendant).
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:boxStrokeColor="#ffcc00"
android:theme="#style/EditTextTheme"
app:layout_constraintEnd_toStartOf="#id/guidelineEnd"
app:layout_constraintStart_toStartOf="#id/guidelineStart"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="1" />
</com.google.android.material.textfield.TextInputLayout>
Applying this fixes the issue but outline border is not achieved in TextInputLayout
styles.xml
<style name="EditTextTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Maybe your Application theme isn't material theme
<style name="AppTheme.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
...
</style>
For example it's like code above. So change it to Theme.MaterialComponents.NoActionBar
But if you don't want change hole theme of your app you may add code below to your layout's root ViewGroup
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/root_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/Theme.MaterialComponents.Bridge">
...
</androidx.constraintlayout.widget.ConstraintLayout>

When using Theme.MaterialComponents the color for + and - in ElegantNumberButton is changing

In order to use Chip and ChipGroup, I set the Application style extends Theme.MaterialComponents
in manifests.xml, then the color of "+" and "-" in ElegantNumberButton is changing before after
This is my style (after using MaterialComponents):
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<!-- <item name="colorPrimary">#android:color/transparent</item>-->
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="colorOnSurface">#color/black</item>
</style>
and this is the button
<com.cepheuen.elegantnumberbutton.view.ElegantNumberButton
android:layout_width="100dp"
android:layout_height="30dp"
android:id="#+id/number_button"
android:layout_marginBottom="18dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
app:backGroundColor="#F42A42"
app:finalNumber="20"
app:initialNumber="1"
app:textSize="8sp"
/>
what can I do?
Looks like your library is not meant to work yet with Material styles. Use the bridge version of the theme,
<style name="AppTheme" parent="Theme.MaterialComponents.Light.Bridge">

Custom Button style is applying partially

Created custom style for button when apply the style for button it is partially. Here is the style code snippet.
Manifest.xml
<application android:theme="#style:AppTheme">
styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:buttonStyle">#style/back_button_style</item>
<item name="buttonStyle">#style/back_button_style</item>
</style>
<style name="back_button_style" parent="Widget.AppCompat.Button">
<item name="background">#drawable/back_button_shape</item>
<item name="android:layout_height">40dp</item>
<item name="android:textColor">#ffffff</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textAlignment">center</item>
<item name="android:textAllCaps">true</item>
<item name="android:layout_marginStart">72dp</item>
<item name="android:layout_marginEnd">72dp</item>
<item name="android:fontFamily">sans-serif</item> //sans-serif nothing but robot regular
</style>
layout.xml
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="continue"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.501"
android:layout_marginBottom="8dp" />
After applying the style only the text color changes to white since i given the text color as white in style but other credentials are not applied background, before applying the button text color was black.
So I not getting why it is partially applying the style.
I tried like this also but it is not working
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="continue"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.501"
android:layout_marginBottom="8dp"
android:theme="#style/back_button_style/>
I am not getting what and where is the bug in the code.
Rectify Button android:theme section .
Don't
android:theme="#style/back_button_style
Do
style="#style/back_button_style"
Then Clean-Rebuild-Run .

Categories

Resources