What is LinearLayoutCompat in appCompat v7? - android

In the support library appCompat v7 of the Android platform, there is a android.support.v7.widget.LinearLayoutCompat class.
Does someone know why this class exist? The original LinearLayout class exist since API level 1 so I don't understand why there is a compat version.

The class LinearLayout exists since API level 1, but some APIs were added after that, for example, setShowDividers introduced on API level 11.
So in this case setShowDividers (and it's parameters) should be invoked using LinearLayoutCompat instead LinearLayout if you are targeting a platform with API level below 11.

Related

Is AppCompat possible to ignore on API 23+?

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 :)

ActionBar does not work, Android

I have a problem with ActionBar.
I set minsdk in AndroidManifest to 14. Next I create Activity (BlankActivity), thats create MyACtivity class which extend ActionBarActivity and import android.support.v7.app.ActionBarActivity. I think that this library need only if you use sdk level 7 or lower.
This import correctly? Or i need use another extend class?
And I try change extend class to Activity, but its does not create ActionBar on Activity.
How add ActionBar on this Activity?
P.S. I was misled, because on my sdk function getActionBar must work, its NullPointer, because my app use this strange import. A can use getSupportActionBar, but its strange use support library for sdk 7 to create Application for sdk 14 or higher.
P.S.S. Thanks!!
If anybody have same problen, there is some links about toolbar:
http://www.101apps.co.za/index.php/articles/using-toolbars-in-your-apps.html
Why was ActionBarActivity deprecated
I have a problem with ActionBar.
Who doesn't ;)
I think that this library need only if you use sdk level 7 or lower.
The appcompat-v7 library used to backport API 14 Action Bar to platforms below that. APIs 7 through 13 used this reimplementation, APIs from 14 used native Action Bar.
Since Lollipop the appcompat-v7 always uses it's own implementation of Action Bar and backports Material theme from Lollipop.
This import correctly? Or i need use another extend class?
To have the Action Bar with appcompat-v7 your activity class must extend AppCompatActivity (previously ActionBarActivity) and it's theme must descend from Theme.AppCompat.* family.
And I try change extend class to Activity, but its does not create ActionBar on Activity.
Native activities on Lollipop don't have any Action Bar by default. You would supply it by having a Toolbar widget in your layout and calling setActionBar(Toolbar). Similar approach can also be used with appcompat-v7 (if you use a theme without default action bar) by calling setSupportActionBar(Toolbar).
How add ActionBar on this Activity?
[...] but its strange use support library for sdk 7 to create Application for sdk 14 or higher.
It's perfectly OK, the goal is to make the app look the same from API 7 to API 22. Appcompat-v7 now backports not only the Action Bar but Material theme as well.
It's better you start with a working example. Just check in you android sdk installation for the folder \samples\android-21\ui\ActionBarCompat-Basic.
The use of the support library is correct, just follow the ActionBar Developer guide here.

Should I use AppCompat v7 if minsdk is 14

should I still use app compat v7 if my app has minSdk = 14?
Is there any advantage with ActionBar in Android L ?
Should I use android.support.v4.app.FragmentActivity from support v4 or should I use the android.app.Activity class (which has support for fragments since honeycomb)?
Should I also use android.app.Fragment or android.support.v4.app.Fragment?
I guess that I should use support v4 FragmentActivity and Fragment, but there is no need for app compat v7, right?
What do you think?
If you want to use Material Design style for SDK 14+, you should also use AppCompat v7:21.0.+
You app can use Material as its main theme, and functional from API 7.
More info you can check this link
AppCompat is used for api level below 11. Since 11 you have action bar natively. So there is no need to use AppCompat on api levle 11 and above.
Extend Activtiy and use Fragment ( not android.support.v4.app.Fragment)

Difference between extending LifecycleActivity,Activity,ActionbarActivity & AppCompactActivity?

In Android what is the main difference between extending Lifecycler Activity, Activity,ActionBarActivity & AppCompactActivity? How do these classes differ from each other in terms of usage?
extending ActionBarActivity gives you the ActionBars functionality on every API level >= 7
by extending Activity you can avoid adding additional projects/libraries to your project but you'll lack the ActionBar on api levels below 11
edit: More details:
ActionBarActivity is part of the Support Library. Support libraries are used to deliver newer features on older platforms. For example the ActionBar was introduced in API 11 and is part of the Activity by default (depending on the theme actually). In contrast there is no ActionBar on the older platforms. So the support library adds a child class of Activity (ActionBarActivity) that provides the ActionBar's functionality and ui
edit2: Update April 2015 - it looks like the ActionBarActivityis deprecated in revision 22.1.0 of the Support Library. AppCompatActivity should be used instead.
edit3: Update Aug 2017 - LifecycleActivity is a LifecycleOwner but:
"Since the Architecture Components are in alpha stage, Fragment and
AppCompatActivity classes cannot implement it (because we cannot add a
dependency from a stable component to an unstable API). Until
Lifecycle is stable, LifecycleActivity and LifecycleFragment classes
are provided for convenience. After the Lifecycles project is
released, support library fragments and activities will implement the
LifecycleOwner interface; LifecycleActivity and LifecycleFragment will
be deprecated at that time."
(copied from the Architecture Components guideline)
If you look carefully, you will see this
public class ActionBarActivity extends FragmentActivity
implements ActionBarDrawerToggle.DelegateProvider TaskStackBuilder.SupportParentable
Here you can read about FragmentActivity:
http://developer.android.com/reference/android/support/v4/app/FragmentActivity.html
And differences between Activity and FragmentActivity:
Difference between Activity and FragmentActivity
Also, there are some new themes for styling actionBar...
https://developer.android.com/training/basics/actionbar/styling.html
Actionbar is introduced in API level 11. com.android.support:appcompat-v7:+ is a support library which allows you to have an ActionBar in your app for devices running on Android 3.0 or below. So, if you need actionbar below api level 11 your Activity needs to extend ActionBarActivity.
If you are targetting api level 11 and above then you don't need to extend ActionBarActivity and reference AppCompat. You can simply extend Activity and you will have actionabr by default.
Android Studio default project includes it automatically in dependencies and extends ActionbarActivity instead of Activity in order to use it.
The ActionBarActivity or the SupportActionBarActivity have additional methods and properties that are not in a generic Activity. for example methods for adding tabs are present in the ActionBarActivity and not in a generic Activity.
The major difference being you don't get an ActionBar on a generic Activity.
ActionBarActivity just has more support libraries and better usage of the newer themes available from api 11.
"In its most basic form, the action bar displays the title for the activity and the app icon on the left. Even in this simple form, the action bar is useful for all activities to inform users about where they are and to maintain a consistent identity for your app."
You are using Android support library When you come to to the Actionbaractivity . so the uses of Support library is your application can be suport for maximum number of devices. Support library gives to your application the power of Backward compatibilty. Actionbaractivity gives you the mulitiple feature like Actionbardrawer toggle etc.. there are more support libraries available. see this link .. and share to your friends...https://developer.android.com/tools/support-library/index.html

How can I style the ActionbarSherlock Tabs in Android API 11+?

I just wanted to give my actionbarsherlock tabs another color. Therefore, I found this interesting article: Styling the Actionbarsherlock tabs
Now, my problem is that for me it only works for API level before 11. What am I doing wrong? I implemented the code from the solution just like that.
One other thing that I did, was increasing my API level (from 7 to 11) because this line from the code in the article
<item name="android:actionBarTabBarStyle">#style/Theme.app.tabbar.style</item>
produced this error:
android:actionBarTabBarStyle requires API level 11 (current min is 7)
Any ideas?
For just API 11+ you can create a folder in res called values-v11 and make a style file in there, then only those styles will be applied if the API is level 11 or greater.

Categories

Resources