<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> </RelativeLayout> <ListView android:id="@+id/drawer_list" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" android:background="#F5F5F5" android:choiceMode="singleChoice" android:divider="#DDDDDD" android:dividerHeight="1dp" /> </android.support.v4.widget.DrawerLayout> public class MainActivity extends AppCompatActivity { private DrawerLayout drawerLayout; private ListView drawerList; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); drawerLayout = findViewById(R.id.drawer_layout); drawerList = findViewById(R.id.drawer_list); drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { } }); } }


上一篇:
下一篇:
切换中文