Hi is there anyone knows how to use the floating action button with andoidx library I think in android x library they replace
implementation 'com.android.support:appcompat-v7:xx.xx.xx'
by
implementation 'androidx.appcompat:appcompat:1.0.0'
but it's not helping any suggetion?
To use Floating action button in andoidx library use below dependencies
implementation 'com.google.android.material:material:1.0.0-rc01'
For more information check Migrating to AndroidX
Complete example
XML code
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/imgFour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_close"
app:backgroundTint="#color/colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tint="#android:color/white" />
Notes
app:tint="#android:color/white" is used to change the icon color of FloatingActionButton
app:backgroundTint="#color/colorAccent" is used to change background color of FloatingActionButton
To use FloatingActionButton inside activity or fragment we need to import FloatingActionButton like this
import com.google.android.material.floatingactionbutton.FloatingActionButton
Now you can migrate to Android x and replace the xml with:
<com.google.android.material.floatingactionbutton.FloatingActionButton ... />
Also in the gradle file add:
implementation 'com.google.android.material:material:1.0.0'
To use Floating action button in androidx library use this implementation
implementation 'com.google.android.material:material:1.0.0'
Related
I´m trying to design a very simple UI for Android using Material Design.
The idea of the login interface is 2 outlined boxes, one for email and one for password. The password box should contain a trailing icon, and if you press that icon it should reveal your password. There is no code problems here, everything it´s supposed to be implemented by Material.io
So the problem I´m facing is about the boxStroke.
When you run the app, you can see clearly the boxStroke (But on the password textBox the trailing icon made dissapear the outline).
Once you focus one of the textBoxes it appears like this:
And you can notice that the outline of the box has totally dissapeared. And it will come back if you add at least one character:
The code for both textBoxes is here, is nearly the same as in the main page of Material.io, I will post at the end of this post the links for the material wiki:
The E-Mail textBox:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/login_email_layout"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="#string/login_hint_email"
app:boxStrokeWidthFocused="3dp"
app:errorEnabled="true"
app:layout_constraintBottom_toTopOf="#+id/login_password_layout"
app:layout_constraintEnd_toEndOf="#+id/imageView"
app:layout_constraintStart_toStartOf="#+id/imageView"
app:layout_constraintTop_toBottomOf="#+id/imageView"
app:shapeAppearanceOverlay="#style/ShapeAppearance.MaterialComponents.SmallComponent">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/textColor" />
</com.google.android.material.textfield.TextInputLayout>
The Password textBox:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/login_password_layout"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="#string/login_hint_password"
app:endIconMode="password_toggle"
app:errorEnabled="true"
app:layout_constraintBottom_toTopOf="#+id/login_forgot_password"
app:layout_constraintEnd_toEndOf="#+id/login_email_layout"
app:layout_constraintStart_toStartOf="#+id/login_email_layout"
app:layout_constraintTop_toBottomOf="#+id/login_email_layout">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:textColor="#color/textColor"
android:visibility="visible" />
</com.google.android.material.textfield.TextInputLayout>
I don't know why the trailing icon is making disappearing the outline neither how can I make that even when empty it should focus the outline. So any help is welcome.
Thanks in advance.
PD: Currently using 1.2.1 material version, tried to switch to 1.3.1-alpha03 version but it will not display anything of the textBox.
Material Outlined Box
EDIT:
Adding graddle:app in case it could give you more info:
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
implementation platform('com.google.firebase:firebase-bom:25.12.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.android.material:material:1.2.1'
implementation 'com.google.gms:google-services:4.3.4'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.19'
implementation 'com.google.android.gms:play-services-auth:18.1.0'
implementation "androidx.navigation:navigation-fragment:2.3.1"
implementation "androidx.navigation:navigation-ui:2.3.1"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
just found the answer:
After a few days I came back to this problem (This was only an aesthetic problem, so I continued programming other things, like the holy Firebase thing).
So the problem was that on styles.xml I had #color/background declared and initialized. And the Material Design API for textEdit was using this color for the outline.
So the solution was to simply remove #color/background. I could have set on the xml file android:background=#null, but have had to do it on every single xml file that used textEdit.
Hope this could help someone and sorry for being so dumb.
As title says, I don't know how to fix this issue. I read this problem but that was in 2018, I'm not very familiar with all those libraries and dependencies how it all works. But judging from my Declared Dependencies, from Android Studio, this is what I got:
I would like to add some kind of "Attach document" icon/image to the FAB. I tried to do this by adding a New Vector asset, but images do not appear in my drawable folder. How can I add a nice icon/image to my project, and set it to a FAB?
Here is XML:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:icon="#drawable/attache_file">
</com.google.android.material.floatingactionbutton.FloatingActionButton>
I found the solution, just add this below statement inside dimens.xml
<dimen name="design_fab_image_size" tools:override="true">56dp</dimen>
And must need to add app:tint="#null" inside your FAB design xml
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="#id/bottomBar"
app:srcCompat="#drawable/ic_logo"
app:tint="#null" />```
Happy to help :)
To use the com.google.android.material.floatingactionbutton.FloatingActionButton add the Material Components library:
implementation 'com.google.android.material:material:1.1.0'
Then use the app:srcCompat attribute:
<com.google.android.material.floatingactionbutton.FloatingActionButton
style="#style/Widget.MaterialComponents.FloatingActionButton"
app:srcCompat="#drawable/..."
.../>
Per the documentation you have to use android:src="#drawable/attache_file"
I'm trying to get run the Extended FAB for my activity, see Screenshot below. It just does not want to run. In my activity xml I use it as follows:
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:layout_constraintBottom_toTopOf="#+id/create_ad_view"
ads:layout_constraintEnd_toEndOf="parent"
ads:layout_constraintStart_toStartOf="parent"
ads:layout_constraintTop_toBottomOf="#+id/create_title_et"
app:icon="#drawable/ic_check"
style="#style/Widget.MaterialComponents.ExtendedFloatingActionButton.Icon"/>
By the way, I used different sources and tutorials, even the official web site of Material Design with some details of using Extended FAB. This is my dependency:
implementation 'com.google.android.material:material:1.0.0'
The ExtendedFloatingActionButton was released with the 1.1.0-alpha04.
Use
implementation 'com.google.android.material:material:1.1.0'
When following this Android tutorial using AppCompat V7 to get the new Tool Bar work, the android.support.v7.widget.Toolbar supports android:elevation on SDK's < Lollipop. This is because they use android.support.v7.widget.Toolbar and not Toolbar.
Is there equivalent for button? Something like android.support.v7.widget.Button? (This one not exist) Or any other workaround in the kind of overlaying the Button in some view supporting elevation? (I don't want implementation of creating custom shapes with gradients for look & feel of elevation).
Thanks,
You can use the Floating Action Button from support design library .
Use below code to the layout where you want this button.
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_fab"
android:layout_gravity="bottom|end"
app:backgroundTint="#0091b4"
app:elevation="6dp"
app:pressedTranslationZ="12dp"
android:layout_margin="10dp"
android:scaleType="centerCrop" />
Do add design dependency in your project
Add below in the dependency list of build.gradle file
compile 'com.android.support:design:23.0.1'
Unfortunately you will have to do what you do not want. Because there is no support button view yet. (As i know :) perhaps some omniscient person will correct my answer)
Is there any standard tools or existing libraries to create a circle button like on Gmail App?
In the android support design support library one of the widgets provided is the Floating Action Button, which is usually added in the bottom right corner(but need not be used only there)
A floating action button is a round button denoting a primary action
on your interface. The Design library’s FloatingActionButton gives you
a single consistent implementation, by default colored using the
colorAccent from your theme.
To get the android design support library in your build.gradle file, add this:
compile 'com.android.support:design:22.2.0'
In your layout file"
<RelativeLayout
...
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.FloatingActionButton
android:id="#+id/myFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="#id/appbar"
app:layout_anchorGravity="bottom|right|end"
android:src="#drawable/ic_discuss"
android:layout_margin="10dp"
android:clickable="true"/>
</RelativeLayout>
Details of android design support library here
Also there are many other libraries providing the FAB like
https://github.com/makovkastar/FloatingActionButton
https://github.com/futuresimple/android-floating-action-button
1.First important thing use Android Studio
2.Add as a dependency to your build.gradle:
dependencies {
compile 'com.melnykov:floatingactionbutton:1.3.0'
}
3. Create a layout
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.melnykov.fab.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="#drawable/ic_action_content_new"
fab:fab_colorNormal="#color/primary"
fab:fab_colorPressed="#color/primary_pressed"
fab:fab_colorRipple="#color/ripple" />
4.Add the namespace
xmlns:fab="http://schemas.android.com/apk/res-auto"
to your layout file.
You can also Set the button type (normal or mini) via the fab_type xml attribute (default is normal):
fab:fab_type="mini"
or
fab.setType(FloatingActionButton.TYPE_MINI);
Yes, with the new Design Support Library a default implementation of the floating action button is provided here.
In order to have access to the new FAB class you will need to add this dependency to your gradle build file.
compile 'com.android.support:design:22.2.0'