Several compatibility issues with APPCOMPAT_V7 21.0.0d

Source: Internet
Author: User

1. Implement a new Actionbardrawertoggle animation



Actionbardrawertoggle using the latest APPCOMPAT_V7 21 will appear a very handsome animation. Use the method below Androidstudio to first join compile

dependencies {    Compile filetree (dir: ' Libs ', include: [' *.jar '])    compile ' com.android.support:appcompat-v7 : 21.0.0 '}

Then direct the Actionbardrawertoggle impot to use the import android.support.v7.app.ActionBarDrawerToggle;

The subsequent construction method will be able to use

Mdrawertoggle = new Actionbardrawertoggle (this, Mdrawerlayout, toolbar, r.string.app_name, r.string.app_name);

Of course a toolbar is needed.


Append: Originally thought needs toolbar The construction method only then has that animation, now discovered originally only must quote the Android.support.v7.app.ActionBarDrawerToggle. Three construction methods all with this very handsome animation

Public Actionbardrawertoggle (android.app.Activity Activity, Android.support.v4.widget.DrawerLayout drawerlayout, int opendrawercontentdescres, int closedrawercontentdescres) {/* Compiled code *    /} public Actionbardrawertoggle ( Android.app.Activity Activity, Android.support.v4.widget.DrawerLayout drawerlayout, Android.support.v7.widget.Toolbar Toolbar, int opendrawercontentdescres, int closedrawercontentdescres) {/* compiled Code */}    <t extends Android.graphics.drawable.Drawable & Android.support.v7.app.actionbardrawertoggle.drawertoggle> Actionbardrawertoggle (android.app.Activity Activity, Android.support.v7.widget.Toolbar Toolbar, android.support.v4.widget.DrawerLayout drawerlayout, T slider, int opendrawercontentdescres, int closedrawercontentdescres) {/* Compiled code */}

2. Replace Actionbar with toolbar

Android L added a new control to replace Actionbar,toolbar with a more flexible extension. Can completely replace Actionbar, and has its own flexibility as a view.

It's just a little inconvenient. Toolbar needs to be declared in every activity, either in XML or in code

    • Change theme
<resources>    <style name= "Apptheme" parent= "Theme.appcompat" >        <!--Customize your Theme here.- -        <item name= "Windowactionbar" >false</item>        <item name= "Android:windownotitle" > True</item>        <!--Actionbar Color--        <item name= "colorprimary" > @color/accent_material_ Dark</item>        <!--Status bar color-->        <item name= "Colorprimarydark" > @color/accent_ Material_light</item>        <!--window color-->        <item name= "Android:windowbackground" > @color /dim_foreground_material_dark</item>    </style></resources>
Suppose you used the Actionbarpulltorefresh control this time to find out. There are two DP intervals between the progress bar and the bottom edge. Assuming toolbar is used, you can control the height of the Actionbar, and of course you can change the Actionbarpulltorefresh source code to solve the problem.
    • Add toolbar to the layout
    <android.support.v7.widget.toolbar        android:id= "@+id/toolbar"        android:layout_width= "Match_parent"        android:layout_height= "wrap_content"        android:minheight= "? attr/actionbarsize"        android:background= " ? attr/colorprimary "        ></android.support.v7.widget.Toolbar>

Toolbar Toolbar = (Toolbar) Findviewbyid (R.id.toolbar); Setsupportactionbar (toolbar);

This has been replaced by a Actionbar toolbar, test found that the internal fragment Getactionbar can be used directly, because in Activiyty toolbar set to Actionbar, So the internal fragment of the Actionbar can be used in the same way as ever.

Of course, you can also set your own toolbar in fragment.
the problem of 3.Actionbar Listmodel dislocation Actionbar.navigation_mode_list after replacing the AppCompat on the 4.x display will appear dislocation, and shows that this method has been discarded. For example with
The solution is to use Tintspinner instead of spinner, it is strange that tintspinner in the official website can not find the relevant information, of course, it is also in the Android.support.v7.internal.widget package. Open to see source code discovery

public class Tintspinner extends Android.widget.Spinner {    private static final int[] Tint_attrs;    Public Tintspinner (Android.content.Context Context) {/* Compiled code *    /} public Tintspinner ( Android.content.Context Context, Android.util.AttributeSet attrs) {/* Compiled code *    /} public Tintspinner (Android . Content. Context context, Android.util.AttributeSet attrs, int defstyleattr) {/* Compiled code */}}

He inherited spinner, but did not do whatever changes, good wonders, replaced and then did conquer the problem.
append: SB, the source code is, just not related to as, but put in: Androidstudio_0_8_14+sdk? Androidsdk? Sources? Android-21? Android? Support? V7? Internal? Widget>tintspinner.java. Source code such as the following
public class Tintspinner extends Spinner {    private static final int[] Tint_attrs = {            Android. R.attr.background,            Android. R.attr.popupbackground    };    Public Tintspinner (Context context) {This        (context, NULL);    }    Public Tintspinner (context context, AttributeSet attrs) {This        (context, Attrs, Android. R.attr.spinnerstyle);    }    Public Tintspinner (context context, AttributeSet attrs, int defstyleattr) {        Super (context, attrs, defstyleattr); C12/>tinttypedarray A = tinttypedarray.obtainstyledattributes (context, Attrs, Tint_attrs,                defstyleattr, 0);        Setbackgrounddrawable (a.getdrawable (0));        if (Build.VERSION.SDK_INT >= && a.hasvalue (1)) {            setpopupbackgrounddrawable (a.getdrawable (1));        }        a.recycle ();    }}





4. To be Continued ...








Several compatibility issues with APPCOMPAT_V7 21.0.0d

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.