DemoActivity.java使用或覆盖已弃用的API。注意:使用-Xlint重新编译:弃用以获取详细信息

时间:2014-12-16 21:00:47

标签: java android multithreading android-gradle lint

我的gradle控制台出现以下错误。尝试寻找已弃用的API但无法找到它。在此先感谢!!!

错误: DemoActivity.java使用或覆盖已弃用的API。注意:重新编译 -Xlint:弃用细节。

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();
        }
        }
    }
}

2 个答案:

答案 0 :(得分:0)

您可能正在使用旧版本的appcompat库。你能展示这个类使用的import语句吗?

基于较新版本的appcompat,请使用

import android.support.v7.app.ActionBarDrawerToggle;

而不是

import android.support.v4.app.ActionBarDrawerToggle;

另外,在build.gradle中引用新版本的appcompat

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

有关已弃用课程的更多信息,请访问:https://developer.android.com/reference/android/support/v4/app/ActionBarDrawerToggle.html

答案 1 :(得分:0)

尝试重建项目。如果仍然不起作用,请尝试链接 https://developer.android.com/reference/android/support/v4/app/ActionBarDrawerToggle.html。造成此问题的主要原因是appcompact库的版本较旧。