I want to center align the text in the extended floating action button but I'm not able to do that. As you can see in the image below the text is not centrally aligned.
Here's is the code for extended floating action button:
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="#+id/compress_start_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="S"
app:backgroundTint="?android:colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:textColor="#color/textColorPrimaryDark"
app:layout_constraintStart_toStartOf="parent"
android:textAlignment="center"
/>
Am I doing anything wrong? Any help will be appreciated.
Please add these two lines in your ExtendedFloatingActionButton
android:paddingStart="0dp"
android:paddingEnd="0dp
use like this
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:layout_width="48dp"
android:layout_height="48dp"
android:gravity="center"
android:paddingStart="0dp"
android:paddingEnd="0dp"
android:text="#string/ic_lin_camera" />
When using an ExtendedFloatingActionButton for text only, in your layout xml for the fab you can use
style="#style/Widget.MaterialComponents.ExtendedFloatingActionButton"
or extend the above style via
<style name="extended_fab_text_only" parent="Widget.MaterialComponents.ExtendedFloatingActionButton">
<item name="android:textAppearance">#style/myTextAppearance</item>
</style>
and you that as the style of your fab in your layout xml
style="#style/extended_fab_text_only"
Documentation: https://material.io/components/buttons-floating-action-button/android#extended-fabs
Under Extended FABs > Styles:
Text-only when extended
style Widget.MaterialComponents.ExtendedFloatingActionButton
Related
This is what is happening
I was following this article Exposed Drop-Down Menu in Android
This is the code that I wrote
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="#color/transparent"
android:backgroundTint="#color/transparent"
app:boxBackgroundColor="#color/transparent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<AutoCompleteTextView
android:id="#+id/autoCompleteT"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:inputType="none"
android:text="Choose Programming language" />
</com.google.android.material.textfield.TextInputLayout>
After digging into the problem I found out that if I delete
<item name="android:background">#color/white</item>
in my theme.xml the problem gets solved. The end icon no longer hides the border. But since I am using this attribute in my project so I can not remove it. I even tried to set the background transparent or #null in both TextInoutLayout and AutoCompleteTextView, nothing happened though.
One last thing this situation won't occur in EditText if I use drawableEnd
How can i change the color of "hint" in my code?
Because with a dark background, i can't see the text and the place where i need to write...
Thank you so much for your help !
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Veuillez taper son prénom ici"
android:textSize="15dp"
android:layout_gravity="center" />
in a <LinearLayout> android:background="#color/colorBlack"/>
In your XML code you can add android:textColorHint :
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Veuillez taper son prénom ici"
android:textSize="15dp"
android:textColorHint="#ff0000"
android:layout_gravity="center" />
OR you can change the hint color programmatically :
edittext.setHintTextColor(Color.RED);
Add id to EditText to identify tag.
.xml file
<EditText
android:id="#+id/ET_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Veuillez taper son prénom ici"
android:textSize="15dp"
android:layout_gravity="center" />
.java file
EditText et_hint = findViewById(R.id.ET_hint);
et_hint.setHintTextColor(getResources().getColor(R.color.white));
Use android:textColorHint="#ff0000" in your xml or edittext.setHintTextColor(Color.BLUE); to set hint color in your Java program grammatically.
if you are using the Material design library. Currently, I am using the version
implementation 'com.google.android.material:material:1.3.0-alpha01'
if you are using the Material design library. Currently, I am using the version
implementation 'com.google.android.material:material:1.3.0-alpha01'
1 - Set color when TextInputLayout is resting.
<item name="android:textColorHint">#color/your_color_hint</item>
2 - Set color when TextInputLayout is floating/focused/tapped.
<item name="hintTextColor">#color/your_color_floating_hint</item>
3 - Set color of the line under TextInputLayout.
<item name="boxStrokeColor">#color/TextViewColor_line</item>
4 - Set color of the error under TextInputLayout.
<item name="boxStrokeErrorColor">#color/colorPrimary</item>
See:
Code:
<RelativeLayout
android:id="#+id/circle_card_payment"
android:layout_width="40dp"
android:layout_height="40dp">
<com.google.android.material.button.MaterialButton
android:id="#+id/logo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:backgroundTint="#color/colorBlack"
android:insetLeft="0dp"
android:insetTop="0dp"
android:insetRight="0dp"
android:insetBottom="0dp"
android:text="W"
android:textColor="#FFFFFF"
android:textSize="16sp"
app:shapeAppearanceOverlay="#style/ShapeAppearanceOverlay_ButtonCircle50"
app:strokeWidth="0dp" />
</RelativeLayout>
style.xml
<style name="ShapeAppearanceOverlay_ButtonCircle50">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">20dp</item>
</style>
For confirmation that material button is containing full space, I sat material button color to black. and inside text color is white.
Can anybody give me the exact solution according to my situation? Please note that you should not increase the relative layout size from 40 to 50 dp, I know that can solve the problem, but logo size will be bigger and that is not appropriate.
Please note, I must need to wrap this button in any root layout. That is mandatory. Like right now my material button is inside Relative layout.
Why does MaterialButton text not containing full space?
The problem is with the material button because by default material buttons have padding. you remove or override that padding by setting padding attribute in the xml itself, this should solve the problem.
just add android:padding = "0dp" to solve this. or as Ricardo.A suggest in comment set in the style <item name="android:padding">0dp</item>
<RelativeLayout
android:id="#+id/circle_card_payment"
android:layout_width="40dp"
android:layout_height="40dp">
<com.google.android.material.button.MaterialButton
android:id="#+id/logo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:backgroundTint="#323232"
android:insetLeft="0dp"
android:insetTop="0dp"
android:insetRight="0dp"
android:padding="0dp"
android:insetBottom="0dp"
android:text="W"
android:textColor="#FFFFFF"
android:textSize="16sp"
app:shapeAppearanceOverlay="#style/ShapeAppearanceOverlay_ButtonCircle50"
app:strokeWidth="0dp" />
</RelativeLayout>
Result with default padding.
and Result with overriding padding to 0dp
Hope this helps, Happy Coding!!
I have tried this solution: https://stackoverflow.com/a/54074154/10299002
which works great as long as the FAB is over a dark background. However, it seems to break when it passes over a white background. What might be the issue?
Here is my FAB:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:theme = "?appAccentStyle"
android:id="#+id/button_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_margin="16dp"
app:backgroundTint="?colorFloatingActionButtonBorder"
android:src="#drawable/ic_arrow_downward_24dp"
android:tint="?colorAccent"
android:backgroundTint="?colorFloatingActionButtonBackground"
tools:visibility="visible"
android:layout_gravity="end|bottom" />
This is the style being applied:
<style name="LimeColorAccent">
<item name="colorAccent">#color/Lime</item>
<item name="appAccentStyle">#style/LimeColorAccent</item>
<item name="colorFloatingActionButtonBorder">#color/LimeTranslucentBorder</item>
<item name="colorFloatingActionButtonBackground">#color/LimeTranslucent</item>
</style>
And here are the colors used:
<color name="Lime">#FFCDDC39</color>
<color name="LimeTranslucentBorder">#4cCDDC39</color>
<color name="LimeTranslucent">#26CDDC39</color>
Output:
Edit:
Tried this solution: https://stackoverflow.com/a/57307389/10299002
My fab.xml:
(Same as in Solution)
My FloatingActionButton:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/button_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_arrow_downward_24dp"
android:background="#drawable/fab"
android:layout_margin="16dp"
android:layout_gravity="end|bottom"
app:fabSize="normal"
app:backgroundTint="#55990000"
app:borderWidth="0dp"
app:elevation="2dp"
tools:visibility="visible" />
Output: (Inner Circle Still Broken)
I used you code and directly used color. and found two result with black background and white background .
and the code:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/button_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
android:layout_margin="16dp"
app:backgroundTint="#4cCDDC39"
android:src="#drawable/ic_action_profile"
android:tint="#color/colorAccent"
app:borderWidth="2dp"
android:backgroundTint="#26CDDC39"
tools:visibility="visible"
android:layout_gravity="end|bottom" />
You should create your own FAB style extending com.google.android.material.floatingactionbutton.FloatingActionButton as parent, to properly custom your button.
Check out this answer, it should help you. The idea is to create your own border.
FloatingActionButton only provides app:borderWidth to play with border thickness.
I want to know why my autocomplete textview suggestion is hiding the autocomplete textview , i am attaching the picture for better understanding.
<AutoCompleteTextView
android:id="#+id/current_location"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/round_background_white"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:paddingLeft="5dp"
android:completionThreshold="1"
android:dropDownHeight="80dp"
android:dropDownWidth="wrap_content"
android:singleLine="true"
android:focusable="true"
android:textColor="#000000"
android:textColorHint="#000000"
android:dropDownListViewStyle="#style/DropDownListViewStyle"/>
Style.xml:
<style name="DropDownListViewStyle">
<item name="android:dividerHeight">2dp</item>
</style>
It's probably due to the custom drawable round_background_white.
Make sure you are specifying enough height & padding in it.
Also post your round_background_white over here.