DemoActivity.java 使用或覆盖已弃用的 API。注意:使用 -Xlint:deprecation 重新编译以获取详细信息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27513833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
DemoActivity.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details
提问by Rg G
i get the following error in my gradle console. Tried looking for the deprecated API but couldn't find it. Thanks in advance!!!
我在 gradle 控制台中收到以下错误。尝试寻找已弃用的 API,但找不到。提前致谢!!!
Error: DemoActivity.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details.
错误:DemoActivity.java 使用或覆盖已弃用的 API。注意:使用 -Xlint:deprecation 重新编译以获取详细信息。
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();
}
}
}
}
采纳答案by AndroidGuy
You are probably using an older version of the appcompat library. Can you show the import statements that this class uses?
您可能正在使用旧版本的 appcompat 库。你能展示这个类使用的导入语句吗?
Based on the newer version of appcompat, use
基于较新版本的 appcompat,使用
import android.support.v7.app.ActionBarDrawerToggle;
instead of
代替
import android.support.v4.app.ActionBarDrawerToggle;
Also, reference the new version of appcompat in build.gradle
另外,在 build.gradle 中引用新版本的 appcompat
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
有关已弃用类的更多信息,请访问:https: //developer.android.com/reference/android/support/v4/app/ActionBarDrawerToggle.html
回答by Siddharth Lal
Try to rebuild the project. If still that doesn't work try link https://developer.android.com/reference/android/support/v4/app/ActionBarDrawerToggle.html. This issue is caused basically due to the older version of appcompact library.
尝试重建项目。如果仍然不起作用,请尝试链接 https://developer.android.com/reference/android/support/v4/app/ActionBarDrawerToggle.html。此问题主要是由于旧版本的 appcompact 库引起的。