1、首先先在res目录下新建一个menu的资源文件,再新建一个menu.xml文件,名字可自取,将以下内容复制过去
<?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、在代码中实现显示三个点
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu,menu);
return true;
}
3、在代码中实现三个点的点击功能
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、不让设置栏遮挡标题栏,只需要在res\values文件夹下的themes文件中添加
<item name="overlapAnchor">false</item>