有没有办法在Android Studio布局编辑器中看到应用于操作栏的自定义布局?

问题描述 投票:0回答:1

假设您没有修改style.xml中的任何属性,Android Studio中的布局编辑器将操作栏显示为:

enter image description here

通过调整操作栏的样式,我可以做一些事情,比如调整它的背景颜色。

但是,我使用的ActionBar是一个使用自定义布局的工具栏,无法通过调整操作栏的属性来简单表达,如下所示。

enter image description here

在运行时期间将上述布局应用于Action Bar并不困难。 (更改自定义视图,或将AppTheme应用于NoActionBar,然后设置SupportActionBar)

我真正想要的是具有这些自定义布局的AppBar将打印出我正在处理的项目中的所有xml,但到目前为止我还没有找到正确答案。

这是Android工作室不支持的操作吗?

android android-studio android-actionbar android-layout-editor
1个回答
0
投票

你可以通过ToolBar和FrameLayouts实现这个目的,

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="?actionBarSize">

    <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="match_parent"
        android:background="?attr/colorPrimary"
        app:contentInsetStart="0dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            //TextView
            //ImageView
            // etc

        </LinearLayout>
    </android.support.v7.widget.Toolbar>
</FrameLayout>


<FrameLayout
    android:id="@+id/main_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="?actionBarSize">
</FrameLayout>

如上所述组织主机活动布局并在main_container中加载片段

© www.soinside.com 2019 - 2024. All rights reserved.