【问题标题】:i have fixed image and texview in toolbar. Now its not showing menus我在工具栏中修复了图像和文本视图。现在它不显示菜单
【发布时间】:2017-11-30 14:29:35
【问题描述】:
  • 为什么不在单击 Image 和 TextView 时显示 menuItem。 请任何人帮助我展示我的 menusItem。 (我使用 app:actionLayout="@layout/login_icon_design")。 当我们删除 app:actionLayout 标签时,菜单就来了。

    //dashboard.xml file
    

    在此处输入代码

    //login_icon_design.xml

    <TextView
        android:id="@+id/qcId"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:paddingLeft="0dp"
        android:text="Active"
        android:textColor="@color/button_green"
        android:textSize="9dp" />
    

    //DashboardActivity.java

      @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
    
            MenuInflater inflater = getMenuInflater();
            inflater.inflate(R.menu.dashboard, menu);
            final Menu m = menu;
            final MenuItem mitem = menu.findItem(R.id.button);
            TextView qcId= (TextView) mitem.getActionView().findViewById(R.id.qcId);
            SharedPreferences pref=this.getSharedPreferences("MyPref",MODE_PRIVATE);
            String refCode=pref.getString("refCode",null);
            qcId.setText(refCode);
    
            Intent intent = getIntent();
            String str2 = intent.getStringExtra("balance");
            menu.findItem(R.id.bal).setTitle("Avl. Bal. \u20B9" +str2);
            return true;
        }
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
    
            int id = item.getItemId();
    
            if(id == R.id.bal) {
    
            } else if(id == R.id.profile){
                Toast.makeText(this, "1", Toast.LENGTH_SHORT).show();
    
            } else if (id == R.id.logout){
                Toast.makeText(this, "2", Toast.LENGTH_SHORT).show();
    
            } else if(id == R.id.event) {
                Toast.makeText(this, "3", Toast.LENGTH_SHORT).show();
    
            } else if(id == R.id.history) {
                Toast.makeText(this, "4", Toast.LENGTH_SHORT).show();
    
            }
            return super.onOptionsItemSelected(item);
        }
    

【问题讨论】:

  • 您必须创建自定义工具栏。但似乎您正在将其添加到默认菜单文件属性中。您可以通过自定义菜单和工具栏来完成。

标签: android xml menuitem submenu


【解决方案1】:

你必须添加这几行

final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多