我创建了一个DrawerLayout,它工作正常.但我希望它在用户触摸背景时关闭.这可以通过实现DrawerLayout与listView但在这里我使用NavigationView.有没有办法实现这一目标?
这是菜单布局 NavigationView
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/home" android:title="Home Parent" android:icon="@drawable/ic_home_black"/>
<item android:id="@+id/send" android:title="Send" android:icon="@drawable/ic_send_black"/>
<item android:id="@+id/add" android:title="Add" android:icon="@drawable/ic_add_black"/>
</menu>
Run Code Online (Sandbox Code Playgroud)
这是java代码
public class ParentActivity extends AppCompatActivity {
private NavigationView mNavigationView;
private User mCurrentUser;
private UserLocalStore mUserLocalStore;
private CircleImageView mProfilePic;
private TextView mProfileName;
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mToggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_parent);
mUserLocalStore = new UserLocalStore(this);
mCurrentUser = mUserLocalStore.getUserDetails();
mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer);
mToggle = new ActionBarDrawerToggle(this,mDrawerLayout,R.string.open,R.string.close);
mDrawerLayout.addDrawerListener(mToggle);
mToggle.syncState(); …Run Code Online (Sandbox Code Playgroud)