我是编程新手,我想添加一个设置菜单按钮。如图所示,我的应用程序不显示三点按钮。MainActivity.java :public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(this, getSupportFragmentManager()); ViewPager viewPager = findViewById(R.id.view_pager); viewPager.setAdapter(sectionsPagerAdapter); TabLayout tabs = findViewById(R.id.tabs); tabs.setupWithViewPager(viewPager); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.settings, menu); return true; } @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { case R.id.vueSatellite: Toast.makeText(this, "Hi", Toast.LENGTH_SHORT).show(); return true; default: return super.onOptionsItemSelected(item); } }}
1 回答
临摹微笑
TA贡献1982条经验 获得超2个赞
在您的活动中只需添加
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);
希望它有效。
添加回答
举报
0/150
提交
取消