2016-03-27 151 views
1

我的应用程序是用Kotlin编写的。我已经去除了默认操作栏:Android:工具栏未显示

<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> 

    ... 

但仍然工具栏没有出现。

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

+1

什么是你布局的休息吗?由于您使用的是RelativeLayout,因此可能是其他孩子躺在工具栏上。 – nhaarman

+0

像Firefox喜欢说的:呃...这很尴尬!你是对的。它被其余的内容所覆盖。竖起大拇指给你! – Ambran

+1

太棒了!有时候另一双眼睛是需要的;-) – nhaarman

回答

0

应设置工具栏高度:

android:layout_height="?attr/actionBarSize" 
+0

这不起作用。即使将其硬编码为100dp也不起作用。 – Ambran

相关问题