所以,我有一个工具栏,我将其设置为supportActionBar,我希望它处于叠加模式.在这一点上,我觉得我已经尝试了一切,但似乎没有任何工作.
这是我目前的风格:
@color/primary
@color/accent
@style/Widget.IconPageIndicator
@style/Widget.TabPageIndicator
false
true
true
@color/background
true
true
这是我的工具栏的代码:
android:id="@+id/actionbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="@style/CustomActionBar"/>
最后,这是我在Activity中设置它的地方:
actionbar = (Toolbar) findViewById(R.id.actionbar);;
setSupportActionBar(actionbar);
我也试过调用getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY)没有运气.
解决方法:
所以,事实证明这个问题同时非常简单,但并不明显(对我来说,至少).基本上问题是尽管工具栏被设置为Actionbar,但它仍然是在一天结束时用XML声明的布局元素.因此,诀窍当然是确保它与XML重叠.这是我的布局中的一个示例,现在:
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:id="@+id/actionbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"/>
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
一切都按预期工作了.希望如果他们遇到同样的问题,这可以帮助别人!
标签:android,appcompat
来源: https://codeday.me/bug/20190609/1206734.html