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"
- Kotlin懒惰的用法
- 如何显示通知抽屉àla Snapchat中不存在的应用内通知
- NoSuchMethodError:beforeCheckcastToFunctionOfArity没有静态方法
- android数据绑定unit testing错误解析数据绑定编译器选项失败。 PARAMS:
- 简化在Kotlin中添加和替换碎片
- 无法使用RxKotlin更改ActionMenuItemView的文本
- kotlin android – 用Builder模式和Java 8 lambda定制对话框
- Android支持库27,片段更新?
- Mocktito ArgumentCaptor Kotlin lambda与参数