DemoActivity.java使用或覆盖脱precated API。注:重新编译-Xlint:详情德precation [英] DemoActivity.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details

查看:413
本文介绍了DemoActivity.java使用或覆盖脱precated API。注:重新编译-Xlint:详情德precation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了我的控制台的gradle下面的错误。试图寻找德precated API,但无法找到它。在此先感谢!

错误:
DemoActivity.java使用或覆盖脱precated API。注:重新编译
-Xlint:德precation详情

 公共类BaseActivity扩展ActionBarActivity {
私有静态最后弦乐TAG =DemoActivity;
DrawerLayout mDrawerlDrawerLayout;
的FrameLayout actContent;
私人的LinearLayout线性的;
私人ActionBarDrawerToggle actionBarToggle;
私人工具栏工具栏;
私人ImageView的mImageView;
私人诠释高度;
私人SlidingUpPanelLayout mSlidingUpPanelLayout;
私人的ListView drawerListView;
私人ArrayAdapter<串GT; navigationDrawerAdapter;
私有String [] = drawerItem {电子邮件,眨眼,收藏,匹配我,关于};    @覆盖
    公共无效的setContentView(最终诠释layoutResID){
    // TODO自动生成方法存根
    线性=(的LinearLayout)getLayoutInflater()膨胀(R.layout.base_activity,NULL);
    actContent =(的FrameLayout)linear.findViewById(R.id.frame_container);
    mDrawerlDrawerLayout =(DrawerLayout)linear.findViewById(R.id.drawer_layout);
    //设置抽屉布局,活动内容base_activity看法。
    工具栏=(栏)linear.findViewById(R.id.main_toolbar);
    setSupportActionBar((工具栏)linear.findViewById(R.id.main_toolbar));
    toolbar.setOnMenuItemClickListener(新Toolbar.OnMenuItemClickListener(){
        @覆盖
        公共布尔onMenuItemClick(菜单项项){
            返回true;
        }
    });
    //充气菜单要显示的工具栏
    toolbar.inflateMenu(R.menu.demo);
    //tool​​bar.getBackground().setAlpha(0);
    getSupportActionBar()setDisplayHomeAsUpEnabled(真)。
    getSupportActionBar()setHomeButtonEnabled(真)。
    getSupportActionBar()setDisplayShowTitleEnabled(假)。    的setContentView(线性);
    //添加BaseActivities布局内framelayout.i.e。 frame_container
    。getLayoutInflater()膨胀(layoutResID,actContent,真正的);    initDrawerView();
    initDrawer();
}@覆盖
公共布尔onCreateOptionsMenu(菜单菜单){
    //充气菜单;如果是present这增加了项目操作栏。
    。getMenuInflater()膨胀(R.menu.demo,菜单);    返回true;
}@覆盖
prepareOptionsMenu(菜单菜单)上公共布尔{
    返回super.on prepareOptionsMenu(菜单);
}@覆盖
公共布尔onOptionsItemSelected(菜单项项){
    Log.e(抽屉,点击);
    如果(actionBarToggle.onOptionsItemSelected(项目)){
        Log.e(抽屉单击的项目,点击);
        返回true;
    }    如果(item.getItemId()== android.R.id.home){
        Log.e(抽屉单击的项目项ID,点击);
        尝试{
            如果(mDrawerlDrawerLayout.isDrawerOpen(drawerListView)){
                mDrawerlDrawerLayout.closeDrawer(drawerListView);
            }其他{
                mDrawerlDrawerLayout.openDrawer(drawerListView);
            }
        }赶上(例外五){
            e.printStackTrace();
        }
        返回true;
    }
    开关(item.getItemId()){
        案例R.id.action_search:{
            返回true;
        }
        案例R.id.action_settings:{
            返回true;
        }    }
    返回super.onOptionsItemSelected(项目);
}私人无效initDrawerView(){
    drawerListView =(ListView控件)findViewById(R.id.list_slidermenu);
    mDrawerlDrawerLayout =(DrawerLayout)findViewById(R.id.drawer_layout);
    navigationDrawerAdapter =新ArrayAdapter<串GT;(BaseActivity.this,
android.R.layout.simple_list_item_1,drawerItem);
    drawerListView.setAdapter(navigationDrawerAdapter);
    drawerListView.setOnItemClickListener(新DrawerItemClickListener());
}私人无效initDrawer(){
    actionBarToggle =新ActionBarDrawerToggle(BaseActivity.this,mDrawerlDrawerLayout,工具栏,
R.string.open_drawer,R.string.close_drawer){        @覆盖
        公共无效onDrawerClosed(查看drawerView){
            super.onDrawerClosed(drawerView);        }        @覆盖
        公共无效onDrawerOpened(查看drawerView){
            super.onDrawerOpened(drawerView);
        }
    };
    mDrawerlDrawerLayout.setDrawerListener(actionBarToggle);
}@覆盖
保护无效onPostCreate(捆绑savedInstanceState){
    super.onPostCreate(savedInstanceState);
    actionBarToggle.syncState();
}@覆盖
公共无效onConfigurationChanged(配置NEWCONFIG){
    super.onConfigurationChanged(NEWCONFIG);
    actionBarToggle.onConfigurationChanged(NEWCONFIG);
}私有类DrawerItemClickListener实现ListView.OnItemClickListener {
    @覆盖
    公共无效onItemClick(适配器视图<>母公司,观景,INT位置,长的id){
        尝试{
            Log.e(抽屉项目点击,点击);
            mDrawerlDrawerLayout.closeDrawers();
        }赶上(例外前){
            ex.printStackTrace();
        }
        }
    }
}


解决方案

您可能正在使用的应用程序兼容性库的旧版本。你能告诉import语句,这个类使用?

根据对应用程序兼容性的新版本中,使用

 进口android.support.v7.app.ActionBarDrawerToggle;

而不是

 进口android.support.v4.app.ActionBarDrawerToggle;

另外,参考应用程序兼容性的新版本中的build.gradle

  {相关性
    编译com.android.support:appcompat-v7:21.0.+
}

更多关于去precated类的:的https://developer.android.com/reference/android/support/v4/app/ActionBarDrawerToggle.html

i get the following error in my gradle console. Tried looking for the deprecated API but couldn't find it. Thanks in advance!!!

Error: DemoActivity.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details.

public class BaseActivity extends ActionBarActivity {
private static final String TAG = "DemoActivity";
DrawerLayout mDrawerlDrawerLayout;
FrameLayout actContent;
private LinearLayout linear;
private ActionBarDrawerToggle actionBarToggle;
private Toolbar toolbar;
private ImageView mImageView;
private int height;
private SlidingUpPanelLayout mSlidingUpPanelLayout;
private ListView drawerListView;
private ArrayAdapter<String> navigationDrawerAdapter;
private String[] drawerItem = {"Email", "Wink", "Favourite", "Match me", "About"};

    @Override
    public void setContentView(final int layoutResID) {
    // TODO Auto-generated method stub


    linear = (LinearLayout) getLayoutInflater().inflate(R.layout.base_activity, null);
    actContent = (FrameLayout) linear.findViewById(R.id.frame_container);
    mDrawerlDrawerLayout = (DrawerLayout) linear.findViewById(R.id.drawer_layout);
    // set the drawer layout as base_activity content view of Activity.


    toolbar = (Toolbar) linear.findViewById(R.id.main_toolbar);
    setSupportActionBar((Toolbar) linear.findViewById(R.id.main_toolbar));
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return true;
        }
    });
    // Inflate a menu to be displayed in the toolbar
    toolbar.inflateMenu(R.menu.demo);
    //toolbar.getBackground().setAlpha(0);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(false);

    setContentView(linear);
    // add layout of BaseActivities inside framelayout.i.e. frame_container
    getLayoutInflater().inflate(layoutResID, actContent, true);

    initDrawerView();
    initDrawer();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.demo, menu);

    return true;
}

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    return super.onPrepareOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Log.e("Drawer", "clicked");
    if (actionBarToggle.onOptionsItemSelected(item)) {
        Log.e("Drawer item clicked", "clicked");
        return true;
    }

    if (item.getItemId() == android.R.id.home) {
        Log.e("Drawer item clicked item id", "clicked");
        try {
            if (mDrawerlDrawerLayout.isDrawerOpen(drawerListView)) {
                mDrawerlDrawerLayout.closeDrawer(drawerListView);
            } else {
                mDrawerlDrawerLayout.openDrawer(drawerListView);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    }
    switch (item.getItemId()) {
        case R.id.action_search: {
            return true;
        }
        case R.id.action_settings: {
            return true;
        }

    }
    return super.onOptionsItemSelected(item);
}

private void initDrawerView() {
    drawerListView = (ListView) findViewById(R.id.list_slidermenu);
    mDrawerlDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    navigationDrawerAdapter = new ArrayAdapter<String>(BaseActivity.this,   
android.R.layout.simple_list_item_1, drawerItem);
    drawerListView.setAdapter(navigationDrawerAdapter);
    drawerListView.setOnItemClickListener(new DrawerItemClickListener());
}

private void initDrawer() {
    actionBarToggle = new ActionBarDrawerToggle(BaseActivity.this, mDrawerlDrawerLayout, toolbar, 
R.string.open_drawer, R.string.close_drawer) {

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);

        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
        }
    };
    mDrawerlDrawerLayout.setDrawerListener(actionBarToggle);
}

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    actionBarToggle.syncState();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    actionBarToggle.onConfigurationChanged(newConfig);
}

private class DrawerItemClickListener implements ListView.OnItemClickListener {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        try {
            Log.e("Drawer item click", "click");
            mDrawerlDrawerLayout.closeDrawers();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        }
    }
}

解决方案

You are probably using an older version of the appcompat library. Can you show the import statements that this class uses?

Based on the newer version of appcompat, use

import android.support.v7.app.ActionBarDrawerToggle;

instead of

import android.support.v4.app.ActionBarDrawerToggle;

Also, reference the new version of appcompat in build.gradle

dependencies {
    compile 'com.android.support:appcompat-v7:21.0.+'
}

More on the deprecated class at: https://developer.android.com/reference/android/support/v4/app/ActionBarDrawerToggle.html

这篇关于DemoActivity.java使用或覆盖脱precated API。注:重新编译-Xlint:详情德precation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆