I am targeting api 17, and I would like to have shadows on devices that support material design. Is there something like "If shadows supported, use shadows"?
Adding android:elevation did solve it.
I thought that this attribute will crash on pre-lollipop devices, as it is not shown in layout editor when minSDK is set to less than 21.
Related
So I have an app in which the user can select a color by choosing from a set of RadioButtons, I have used the ButtonTint XML attribute to color the buttons, but obviously this only works on API > 21/.
so my question is,
how to change the color of the RadioButtons on KitKat(API 19) and below?
I have tested a few methods from other stack overflow questions, but so far none have worked.
Use design support library (23.2.0 OR latest) and appcompatwidgets as below
Material Design for Pre-Lollipop Devices :
AppCompat (aka ActionBarCompat) started out as a backport of the
Android 4.0 ActionBar API for devices running on Gingerbread,
providing a common API layer on top of the backported implementation
and the framework implementation. AppCompat v21 delivers an API and
feature-set that is up-to-date with Android 5.0
Android Support Library 22.1 :
The ability to tint widgets automatically when using AppCompat is
incredibly helpful in keeping strong branding and consistency
throughout your app. This is done automatically when inflating layouts
- replacing Button with AppCompatButton, TextView with AppCompatTextView, etc. to ensure that each could support tinting. In
this release, those tint aware widgets are now publicly available,
allowing you to keep tinting support even if you need to subclass one
of the supported widgets.
This tint aware widgets are now publicly available, allowing you to keep tinting support even if you need to subclass one of the supported widgets.
From link above,
The full list of tint aware widgets at this time is:
AppCompatAutoCompleteTextView
AppCompatButton
AppCompatCheckBox
AppCompatCheckedTextView
AppCompatEditText
AppCompatMultiAutoCompleteTextView
AppCompatRadioButton
AppCompatRatingBar
AppCompatSpinner
AppCompatTextView
I need to know what actual difference between TextView and TextViewCompat.
When we should use TextViewCompat?
In much the same way as other compatibility classes, it exists to provide backwards compatibility for new functions to older versions of Android.
If you compare the two, you will see the difference.
One such example is getMaxLines(). In an ordinary TextView, this requires SDK level 16. TextViewCompat introduces such functions for SDK levels from 4.
define TextViewCompat in developer.android
A TextView which supports compatible features on older version of the platform, including:
Supports textAllCaps style attribute which works back to Gingerbread.
Allows dynamic tint of it background via the background tint methods in ViewCompat.
Allows setting of the background tint using backgroundTint and backgroundTintMode.
Hi I'm trying to apply a shadow to a linearlayout with the following code
if (<some condition>)
layout.setElevation(4);
but this call requires API level 21 to work. How can I apply a shadow to layouts for devices with version < 5.0? Is it possible?
I know this is part of Material Design which is why I just want to know if there is a way to achieve something similar in previous versions, thanks :)
Use ViewCompat.setElevation(view, elevation);
I'm using com.android.support:appcompat-v7:22.2.0 to make Lolipop material design on pre-Lolipop devices. The problem is that widgets (example EditText) are displaying different views with different parameters on different API.
Question is how to make it all looks the same on all API 15 and above?
Example here (different bottom line, margin between text and line etc.):
I think that I found solution.
AppCompat generates proper look during inflating layout.
If API < 20 it generates look like newest API (ex. 22).
If API >= 21 it generates look depending on API.
Don't look at preview in XML (my image is from previews). Open emulator and check by yourself how it will looks on device.
Hope it helps someone in future.
I'm going to develop an android application in our school as a project.
I want to use the new Material Design by Google but i know its only available on Android-L Devices.
Jack Underwood has recently released the calendar called "Today Calendar", which is in the Material Style and running on Kitkat and lower Devices.
I know that the Actionbar height is a bit bigger than the older one and the navigation drawer toggle has a new style. And so one ...
How do i implement that?
Currently the Android-L contains the Material Theme which works only on Android-L release.
You can build a Material Style without this Theme.
For example:
you can use a custom ActionBar (it is a customView) with a solid color, without shadow and with the navdrawer icon insted of standard icon app.
You can build a subheader bar with a LinearLayout below the actionBar with the same color.
You can build a Floating Action Button with a floating circle (and a shadow in png)
and so on...
We don't know what will be available for older releases. May be something as the new class Toolbar will be available in support library (and it will semplify the actionbar).
I suggest you waiting a month.
appcompat v21 supports the toolbar on pre-lollipop devices as well.
You can check out Chris's blog for some help on this
https://chris.banes.me/2014/10/17/appcompat-v21/
Of course, the elevation attributes does not work on pre-lollipop devices, so you need to implement custom shadow for version < 21. I would suggest a gradient drawable with height around 4dp works fine.