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'
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.
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)
I'm looking to make a new app, using only API 21.
To follow the Material Design, I'm trying to use a FAB, but I cannot find any decent information on how to use the one now included in the Design Library.
So far, I have added the library the the build.gradle file, and added a FAB to my view (code below)
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:src="#android:drawable/ic_menu_add"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
app:elevation="5dp"
app:borderWidth="0dp"
app:fabSize="mini"/>
(This is in a RelativeLayout)
When I launch the app, I get:
android.view.InflateException: Binary XML file line #15: Error
inflating class android.support.design.widget.FloatingActionButton
I found one answer on SO that says I need to use an AppCompat theme, but I'd rather just use pure Material/API21 stuff.
How can I use a FAB without AppCompat (support libraries)?
The FAB is built into the new Design Compat library - which will work on devices as early as API 7. You will need to include it as a dependency to use it (and shouldn't hesitate to do so).
If you want to avoid using a library (or any external code) you will need to draw the FAB yourself (using a Shape Drawable).
Bottom line, using the Design Compat lib is the preferred method for supporting a FAB, and you should use it. The Design Compat lib IS the "pure/Material API21 stuff".
There is NOT a FAB implementation implemented for any API other then the one in the Design support lib. You have to include the lib, or implement the code entirely yourself.
The Design lib has a dependency on AppCompat, so if you are planning on using the native fab, you will also need to include the dependency for AppCompat.
From the official blog post: "Note that as the Design library depends on the Support v4 and AppCompat Support Libraries, those will be included automatically when you add the Design library dependency."
The Material Design library has a dependency with AppCompat.
Check the #Booger answer. It reports the official blog.
How to use a FAB.
Add the dependency to your build.gradle:
compile 'com.android.support:design:22.2.0'
Just add the FAB to your design:
<android.support.design.widget.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:src="#drawable/ic_add"
android:layout_marginBottom="#dimen/fab_margin_bottom"
android:layout_marginRight="#dimen/fab_margin_right"
app:elevation="6dp"
app:borderWidth="0dp"
app:fabSize="normal" />
Currently there are some bugs.
You have to define app:borderWidth="0dp" to display the shadow with API21+.
Also you have to define different margins for API 21+ and older devices.
res/values/dimens.xml
<dimen name="fab_margin_right">0dp</dimen>
<dimen name="fab_margin_bottom">0dp</dimen>
res/values-v21/dimens.xml
<dimen name="fab_margin_right">16dp</dimen>
<dimen name="fab_margin_bottom">16dp</dimen>
FAB uses the accent color and you could override with app:backgroundTint attribute.
Finally you can set a ClickListener with:
fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//do something
}
});
Actually I was having the same problem. The solution was quite simple:
you have to define app:rippleColor="#color/colorPrimary"
and you can use a FAB without using Appcompat Themes and Activities. Of course you have to include compile 'com.android.support:support-v4:25.3.1' and compile 'com.android.support:design:25.3.1'
but you DO NOT have to use AppCompatActivity and those Themes.
<android.support.design.widget.FloatingActionButton
android:id="#+id/action_add_palette"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:src="#android:drawable/ic_input_add"
app:rippleColor="#color/colorPrimary" />
There is also several popular libraries on GitHub like:
FloatingActionButton which can expand/collapse as menu to reveal multiple actions.
I would say that although you intend to make your app available on API21 only but I encourage you to implement your application using Android Support Library AppCompat-v7 anyway. There are a lot of benefits you will get.
Anyway it is your choice. Just my suggestion. But if you are convinced. Or check out this full tutorial about how to use Android Design Support Library. http://inthecheesefactory.com/blog/android-design-support-library-codelab/en
Hope this help
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'
Is there a way I can Achieve the floating button to work on 4.0 and later android??
I've seen it on google plus but I haven't found any tutorial. Only for android l preview. What did google+ use to achieve it?
You can now use the FloatingActionButton from the support-design library. Add this dependency to your gradle build file:
compile 'com.android.support:design:22.2.0'
And then add the FloatingActionButton to your layout file:
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/ic_done" />
Example project from Chris Banes: https://github.com/chrisbanes/cheesesquare.
I created an open-source library called FloatingActionButton. It's a Google+ like floating action button which reacts on the list view scrolling events. Becomes visible when the list view is scrolled up and invisible when scrolled down. API level 14+.
Here is one aditional free Floating Action Button library for Android
It has many customizations and requires SDK version 9 and higher
Full Demo Video
dependencies {
compile 'com.scalified:fab:1.1.2'
}
Original post is here.
You can use this library, it works well from the Android 2.1, API level 7.
It's so easy to include it in your project:
build.gradle
dependencies {
compile 'com.shamanland:fab:0.0.6'
}
layout.xml
<com.shamanland.fab.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/your_image"
/>
You can use this demo FloatingView. This demo work from API 11.
Here put all the parts necessary to implement by code. FloatingView by steps
Try this library, https://github.com/navasmdc/MaterialDesignLibrary
It can be easily to adapt to your project using Android Studio