I would like to Tint my ToggleButton, which doesn't available in Tintable View support library. Currently I am using appcompat support library v23.1.0
To make ViewCompat.setBackgroundTintList() works, the View needs to implement TintableBackgroundView.
However, there is almost 0 example of how to do this. I looked into the source code of AppCompatButton (which implements TintableBackgroundView), it used of a private class AppCompatBackgroundHelper, which is not accessible outside of the support library.
Any idea?
Related
I am developing an Android Project from scratch that has min 23 API level and uses AndroidX. When I complete the XML layouts (for ex. simple activity_layout) there is options to pick like between TextView & androidx.appcompat.widget.AppCompatTextView.
Is TextView targeting AndroidX?
If yes, can I ignore using androidx.appcompat.widget.AppCompatTextView or other AppCompat component if I target min 23 API level?
Is TextView targeting AndroidX?
The question in not clear but the class androidx.appcompat.widget.AppCompatTextView extends android.widget.TextView.
You can check the official doc.
A TextView which supports compatible features on older versions of the platform.
Also:
This will automatically be used when you use TextView in your layouts and the top-level activity / dialog is provided by appcompat. You should only need to manually use this class when writing custom views.
Then.
If yes, can I ignore using androidx.appcompat.widget.AppCompatTextView or other AppCompat component if I target min 23 API level?
You can ignore this view if you are using the androidx.appcompat:appcompat:x.y.z library.
from the standard android documentation for AppCompatTextView:
This will automatically be used when you use TextView in your layouts
and the top-level activity / dialog is provided by appcompat. You
should only need to manually use this class when writing custom views.
taken from here : https://developer.android.com/reference/android/support/v7/widget/AppCompatTextView , so yes, you can just use TextView as long as your activity extends AppCompatActivity
As pointed out by #Gabriele Mariotti (thank you to him) you should check out the documentation here https://developer.android.com/reference/kotlin/androidx/appcompat/widget/AppCompatTextView for more information regarding androidx AppCompatTextView documentation specifically.
The androidX documentation states the following regarding an AppCompatTextView:
This will automatically be used when you use TextView in your layouts
and the top-level activity / dialog is provided by appcompat. You
should only need to manually use this class when writing custom views
an exact duplicate of the standard android documentation.
My initial answer only made use of this : https://developer.android.com/jetpack/androidx/releases/appcompat to check for any known limitations or history regarding androidx AppCompatTextView
I assumed that:
Like the Support Library, AndroidX ships separately from the Android
OS and provides backwards-compatibility across Android releases.
AndroidX fully replaces the Support Library by providing feature
parity and new libraries.
taken from https://developer.android.com/jetpack/androidx would be sufficient to make that assumption, +1 to him for the help :)
Android Studio marks as error this line:
public class ParallaxView extends ImageView
Here the error:
This custom view should extend android.support.v7.widget.AppCompatImageView instead less... (Ctrl+F1)
In order to support features such as tinting, the appcompat library will automatically load special appcompat replacements for the builtin widgets.
However, this does not work for your own custom views. Instead of extending the android.widget classes directly, you should instead extend one of the delegate classes in android.support.v7.widget.AppCompat.
It recommends me to extend AppCompatImageView but then my JUnit test don't pass because AppCompatImageView needs a mock Context with resources and Imageview doesn't need this.
Here the question to solve the other problem:
NullPointerException creating an AppCompatImageView with mock Context
Can I ignore this error and use ImageView? Any other solution?
Using AppCompat widgets allows you to have some material design (and other new) features on devices with pre-Lollipop versions of Android.
At this point AppCompatImageView only provides the support for background tint and vector drawables. If you don't use them, then extending the regular ImageView will be fine.
It's not really an error. The app builds successfully right? It's only Android Studio which marks it as error.
You can change this to warning by editing the 'Appcompat Custom Widgets' inspection settings.
I'm making library that extends from TextView and ImageView. Someone requested me to extend from AppCompatTextView and AppCompatImageView instead so that it would be backward compatible (to I don't know what version... can't find the info).
My library already being used by others. If I change my library to extends from AppCompatTextView and AppCompatImageView instead of from TextView and ImageView, will there be impact to my existing user in term or usage (e.g. they have to modify their code, xml attribute)... or performance (e.g. slower, memory)? Or it is pure gain, i.e. AppCompat version is the superset of the normal version, and AppCompat is more backward compatible?
Given the following:
Android documentation says :
AppCompatActivity - Adds an application activity class that can be used as a base class for activities that use the Support Library action bar implementation.
I'm not considering adding action bar to my activity
I need some material design widgets, which I can control only through AppCompat or material theme, but the latest need API >= 21, which is not my case.
I tested Theme.AppCompat.Light.NoActionBar with Activity class and it works well.
--
Is there an issue with using Activity class with AppCompat theme in my case?
The AppCompat library is intended to make compatibility with olders API, so the Theme and all components may work well in older systems.
I think the only concern is to always use the AppCompat elements and not the regular ones.
Example, use AppCompatEditText, AppCompatTextView, etc... And always refers to they with the AppCompat (AppCompatEditText editText;)
I have used a lot the support library and not have others issues, considering the visual elements may be a little different when using an API minor than 21
No.There is not issues with AppcompactActivity & support libaray. You can refere this link
To gain more rich & amazing look go with support library,Try to do material design
It seems that there is no way to activate color tinting on standard controls (EditBox and CheckBox) on KitKat with new android support v7 library (appcompact). I have tried everything.
I have followed instructions from offical android blog post to the letter:
http://android-developers.blogspot.com/2014/10/appcompat-v21-material-design-for-pre.html
And I got everything working in short time without problems, except color tinting for EditBox and CheckBox.
I am not using some custom edit control (only standard android widgets), and I'm inflating all my layouts using LayoutInflater in fragments. I can only see effects of tinting with new 'SwitchCompat' widget. Oh, just to mention that I've set colorAccent in my theme.
Any ideas, what can I do to make it happen ?
After long struggle :) I got it to work !
Here is how:
All of your Activities must extend from ActionBarActivity, not from FragmentActivity, regardless if you are using actionbar or not, this is a must for tinting in support library.
Second, if you are using adapter for listview LayoutInflater for adapter must be created using themed activity as context, and for that matter any LayoutInflater that you are using must be provided by properly themed activity.