1. First, create a menu resource file in the res directory, and then create a menu.xml file. The name can be chosen by yourself. Copy the following content to the past
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu1"
android:orderInCategory="101"
app:showAsAction="never"
android:title="test1" />
<item
android:id="@+id/menu2"
android:orderInCategory="101"
app:showAsAction="never"
android:title="test2" />
</menu>
2. Realize the display of three points in the code
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu,menu);
return true;
}
3. Implement the click function of three points in the code
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()){
case R.id.menu1:
Toast.makeText(getApplicationContext(),"1",Toast.LENGTH_SHORT).show();
break;
case R.id.menu2:
Toast.makeText(getApplicationContext(),"2",Toast.LENGTH_SHORT).show();
break;
}
return super.onOptionsItemSelected(item);
}
4. Do not let the setting bar cover the title bar, just add it to the themes file under the res\values folder
<item name="overlapAnchor">false</item>