Android - FloatingActionButton on Other theme - android

I have to implement FloatingActionButton in my company's Android Application.
The problem is, the app is pre-style with Holo theme. When I ran the app, it crashed, the error is
"java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.AppCompat".
So, the question is: Is there a way to implement FloatingActionButton without AppCompat theme.

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.
"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."

Related

Is AppCompat libraries still neccessary?

With the number of users moving to 7+ android version, is AppCompat still necessary or can I use the new libraries instead. This is specially related to styling. I want to switch to the Material design library for styling. What i'm asking is, is it recommend to use the new Material design library versus AppCompat?
The Material Design Components are built on top of AppCompat, so while you may use Material styles in place of AppCompat, you still need AppCompat under the hood to provide a consistent base across all API levels. This also means you need to continue to extend AppCompatActivity, etc.

Why can't I use a FloatingActionButton in Activity

I am very new to Android Development, but can I ask why the FAB is not supported in Activity and only in AppCompactActivity. Correct me if I am wrong but it's my understanding that as long as you are not bothered with backwards compatibility then using Activity is the one to use as you can directly implement material themes and use the latest material design like CardViews RecyclerViews and other layouts like CoordinatorLayout. Why then when you want to use a material design feature like the FAB does it force you to use the AppCompactActivity, I thought using the one supporting higher APIs would work. Am I missing something here, I know there are third party libs I can use, but I really need to get my head around this...
FloatingActionButton is not a part of core android library. Rather it is a part of android support design library.
compile "com.android.support:design:27.0.2"
This means this class is not pre-installed in android devices. Also to use it, your activity must use one of the AppCompat themes. Hence you need to use appcompat library to use a default FAB.
compile "com.android.support:appcompat-v7:27.0.2"
However, you can find many open source third party libraries for FAB in GitHub.

Dumping AppCompat for API 21

So I'm creating an app that is Lollipop 5.0 API 21 and up with zero interest in supporting older devices. Do I still need the appcompat library when using Material Design like UI elements & layouting (sidebar aka nav bar, ink, etc) ? When stripping it down I often encounter crashes when trying to move away from the AppCompat stuff. Changing activity types from the AppCompat one to the Normal one, I end up with problems regarding dependencies on layout types like the coordinator layout that aren't there.
I'm still new to android and this is very confusing, as my theme is currently in limbo somewhere between the appcompat theme & material design when I tried to change it from one of the template.
I've read that this is an android studio issue because it always uses appcompat regardless of your set dependencies & minimum API levels. Forcing you to manually override every implicit hidden appcompat call.
When trying to dump AppCompat, what changes to I need to do to make that happen ? Manifest, Activities, Menus, Layout, Styles ? It seems to touch all these things. If going exclusive without Appcompat, do you still need the v21 folders or will it grab the default ones ?
Do I still need the appcompat library when using Material Design like UI elements & layouting (sidebar aka nav bar, ink, etc) ?
If you are using classes out of the Design Support library, such as NavigationView, you generally need to use appcompat-v7 and AppCompatActivity. As of early May 2016, Google has not shipped a Design Support library analogue that works with Theme.Material. You may be able to find third-party library replacements for some of those widgets, and seasoned Android developers can sometimes "cross-port" these components to eliminate the appcompat-v7 dependencies.
I've read that this is an android studio issue because it always uses appcompat regardless of your set dependencies & minimum API levels. Forcing you to manually override every implicit hidden appcompat call.
The only place that Android Studio really cares about appcompat-v7 is in the new-activity wizards, which you do not have to use.
When trying to dump AppCompat, what changes to I need to do to make that happen ? Manifest, Activities, Menus, Layout, Styles ?
That is difficult to answer in the abstract. You would need to:
Stop using Design Support library widgets and containers
Stop inheriting from AppCompatActivity
Change your app: attributes in your menu resources to their android: equivalents
Change your theme to not use Theme.AppCompat
If going exclusive without Appcompat, do you still need the v21 folders or will it grab the default ones ?
-v21 resource directories are not tied to appcompat-v7. They will still be used, on API Level 21+ devices.

In Android, how can I use TextInputLayout and Snackbar without the Design Support Library

I am developing a new Android project with a minimum SDK set at 5.0. I want to use material design, but it seems like many of the material design components are only included in the support library. I really want to theme the app as Material, not AppCompat.
When I try to add a layout from the support library, I get an error every time. What do I need to do to remove the support library dependencies?
The Snackbar is only available in the design support library - it is not baked into versions of Android like EditText/ImageView views.

Android AppCompat ProgressDialog?

I want to style all the android.app.ProgressDialogs in my app on pre-Lollipop versions to make them look like Material Design.
Maybe I'm missing something obvious: I'm looking for android.support.v7.app.ProgressDialog, but there is no such class in Android AppCompat library.
Should I write my own implementation of ProgressDialog from scratch? What is the reason it's not included in AppCompat library?
Widget.AppCompat.* styles can be used starting from API 7.
There is currently no AppCompat style for the progress dialog since it relies on AnimatedVectorDrawable.
However, it's possible to write a custom drawable that has the same behavior and apply it to your ProgressDialog.
check out GIT
You can use other cool compatibility libraries besides AppCompat.
There are cool libraries which brings fully animated Material Design components to pre-Lolipop Android on Github. The images are from Rey5137's "Material" library. You better use one of such libraries rather that writing from scratch.

Categories

Resources