Android:工具栏不显示

我的应用程序是用Kotlin编写的。 我已经删除了默认的操作栏:

<resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> <style name="FullscreenTheme" parent="AppTheme"> <item name="android:actionBarStyle">@style/FullscreenActionBarStyle</item> <item name="android:windowActionBarOverlay">true</item> <item name="android:windowBackground">@null</item> <item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item> <item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item> </style> <style name="FullscreenActionBarStyle" parent="Widget.AppCompat.ActionBar"> <item name="android:background">@color/black_overlay</item> </style> <style name="Toolbar" parent="ThemeOverlay.AppCompat.Dark"> </style> </resources> 

然后,我在活动中声明了自己的工具栏:

 class ResultActivity : AppCompatActivity() { var mToolbar: Toolbar? = null var realmRecyclerView: RealmRecyclerView? = null var flightAdapter: FlightRecyclerViewAdapter? = null var realmAccess: RealmAccess? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_result) mToolbar = findViewById(R.id.toolbar) as Toolbar realmAccess = RealmAccess(baseContext) realmRecyclerView = findViewById(R.id.realm_recycler_view) as RealmRecyclerView? // Set up the action bar. setSupportActionBar(mToolbar) //supportActionBar!!.setDisplayShowTitleEnabled(true) ... 

还添加了XML:

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".activity.ResultActivity"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/colorPrimary" android:minHeight="50dp" app:theme="@style/Toolbar"> <TextView android:id="@+id/toolbar_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="Toolbar Title" /> </android.support.v7.widget.Toolbar> ... 

但是工具栏仍然不显示。

我在以前的应用程序中以相同的方式完成了这项工作,并取得了良好的效果,但我无法看到问题出在哪里。

您应该设置工具栏高度:

 android:layout_height="?attr/actionBarSize"