【问题标题】:transparent toolbar for Navigational Drawer theme of Android Studio with image overlapping toolbarAndroid Studio导航抽屉主题的透明工具栏,带有图像重叠工具栏
【发布时间】:2016-03-15 11:38:18
【问题描述】:

我是 Android 设计的新手。我有 Android Studio 的 Navigational DrawerLayout,当我的应用加载时,我正在为应用加载 Initial Fragment

  1. 我想让toolbar 透明
  2. 我想要一个与DrawerLayout's toolbar 重叠的图像
  3. 对于其他 Fragments,我希望相同的 toolbar 不透明。

应用加载时的第一个屏幕

当任何其他片段被调用时

【问题讨论】:

  • 当然,您“谷歌搜索了几个小时,但找不到一篇文章”,对吧?
  • @Marcin Orlowski 是的。

标签: java android android-fragments android-studio


【解决方案1】:

没有:1。

您只需定义隐藏操作栏的主题,定义具有透明背景的操作栏样式并将此样式设置为工具栏小部件。请注意,工具栏应作为最后一个视图绘制(在所有视图树上)

<style name="Theme.Custom" parent="@android:style/Theme.AppCompat">
    <item name="windowActionBar">false</item>
    <item name="windowActionBarOverlay">true</item>
    <item name="android:windowActionBarOverlay">true</item>
</style>

<style name="CustomActionBar" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="android:windowActionBarOverlay">true</item>
    <!-- Support library compatibility -->
    <item name="windowActionBarOverlay">true</item>
</style>

布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Toolbar should be above content-->
    <include layout="@layout/toolbar" />

</RelativeLayout>

工具栏布局:

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:theme="@style/CustomActionBar"/>

否:2

将 ImageView 放在相对布局中。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!-- Toolbar should be above content-->
        <include layout="@layout/toolbar" />


        <ImageView          
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:scaleType="centerInside"
                android:adjustViewBounds="true"
                android:transitionName="photo_hero"
                android:id="@+id/image"
                />
    </RelativeLayout>

工具栏布局:

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:theme="@style/CustomActionBar"/>   

【讨论】:

  • 感谢您的解决方案,我会尝试的。我有一个基本问题,我是否必须在每个片段中使用工具栏?现在我有一个来自 mainActivity 的通用工具栏。
猜你喜欢
  • 2015-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-23
  • 1970-01-01
  • 1970-01-01
  • 2019-09-15
  • 2017-04-14
相关资源
最近更新 更多