mDrawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
我曾經有這行代碼禁用滑動手勢,但頂部切換按鈕打開抽屜。我發現支持庫的最新更新後,它不再正常工作。我無法通過切換按鈕或滑動手勢打開抽屜。我需要取消註釋以打開抽屜。無法使用按鈕在最近更新後使用LOCK_MODE_LOCKED_CLOSED打開抽屜
有誰知道需要改變什麼?
我也將setDrawerListener
更改爲addDrawerListener
,因爲前者折舊。
public abstract class BaseActivity extends AppCompatActivity {
protected DrawerLayout mDrawer;
ActionBarDrawerToggle actionBarDrawerToggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_base);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
mDrawer = (DrawerLayout) findViewById(R.id.navigation_drawer);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
actionBarDrawerToggle = new ActionBarDrawerToggle(this,mDrawer,toolbar,0,0);
mDrawer.addDrawerListener(actionBarDrawerToggle);
// Disable drawer's swiping function
mDrawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View contentView = inflater.inflate(getLayoutResource(), null, false);
FrameLayout mainContent = (FrameLayout) findViewById(R.id.main_content);
mainContent.addView(contentView, 0);
inflateDrawerItem();
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}