Java 无法在工具栏上显示图标

Java 无法在工具栏上显示图标,java,android,xml,android-actionbar,android-toolbar,Java,Android,Xml,Android Actionbar,Android Toolbar,我尝试了所有的解决方案,但仍然无法在工具栏上显示图标,在我的主项目中,我有一个工具栏,在它下面是工具栏,在工具栏内部是碎片,无论我尝试了什么,我都无法在工具栏上显示图标,这里是mainActivity.java,它扩展了AppActivity protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activit

我尝试了所有的解决方案,但仍然无法在工具栏上显示图标,在我的主项目中,我有一个工具栏,在它下面是工具栏,在工具栏内部是碎片,无论我尝试了什么,我都无法在工具栏上显示图标,这里是mainActivity.java,它扩展了AppActivity

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_act_main_screen);

    Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
    setSupportActionBar(myToolbar);

    ActionBar ab = getSupportActionBar();
    ab.setTitle("Title");


    tabs = (TabLayout) findViewById(R.id.tabs);
    tabs.addTab(tabs.newTab().setText("Today"),true);
    tabs.addTab(tabs.newTab().setText("Settings"));

    tabs.setOnTabSelectedListener(this);
}

     @Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}
styles.xml

 <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
 </style>

menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"


mainactivity.xml

<android.support.v7.widget.Toolbar
    android:id="@+id/my_toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/toolbarColor"
    android:elevation="3dp">
</android.support.v7.widget.Toolbar>

<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabGravity="fill"
    app:tabMode="fixed"
     />


什么都不起作用,不知道如何实现自定义名称空间,但我将名称从app更改为custom,但不起作用。还有足够的空间,但仍然无法显示。

在活动类上,您需要:

 @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu, menu);
        return true;
    }

我总是这样做工具栏的标题和图标:

因为我现在无法使用计算机,所以我无法发布完整的示例,但我将描述:

首先像这样设置你的
工具栏的高度:
layout\u height=“android:?attr/actionBarSize”
,然后在
android.support.v7.widget.toolbar
标签中放置一个
LinearLayout
带有以下属性的
android:layout\u width=“match\u parent
android:layout\u height=“match\u parent“
android:gravity=“center_vertical | left”
然后在
线性布局中放置一个
ImageView
,并具有以下属性:

width="wrap_content"
height="match_parent"
scaleType="fitXY"
adjustviewbounds="true"
src="@drawable/icon"
如果要添加标题,只需在添加图像视图后添加文本视图。

尝试同时使用这两种视图

  android:showAsAction="always"
  app:showAsAction="always"

忽略你应该使用
app:showAsAction的警告

我想我忘了添加问题中添加的帖子请查看更新的问题我做了,你可以看到发布的问题,无论是一起还是单独
  android:showAsAction="always"
  app:showAsAction="always"