我的应用程序是用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>
...
但工具栏仍然没有显示出来。
我在以前的应用程序中以相同的方式完成了这项工作并取得了良好的效果,我无法在这里看到问题所在。
答案 0 :(得分:0)
您应该设置工具栏高度:
android:layout_height="?attr/actionBarSize"