gpt4 book ai didi

带有透明工具栏的Android DrawerLayout

转载 作者:太空狗 更新时间:2023-10-29 16:27:24 27 4
gpt4 key购买 nike

我正在尝试创建一个带有透明 Toolbar(带有汉堡图标)和 NavigationViewDrawerLayout

这是我的 main_activty 的布局:

<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<include
layout="@layout/app_bar_map"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer"
app:itemTextColor="@color/primary"
android:background="@color/secondary"/>

</android.support.v4.widget.DrawerLayout>

这就是我定义 app_bar_map 布局的方式:

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

<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".core.MainActivity">

<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</android.support.design.widget.CoordinatorLayout>

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" />

</android.support.design.widget.AppBarLayout>

</RelativeLayout>

最后,这是 onCreate 方法的代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

MapFragment mapFragment = new MapFragment();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, mapFragment);
fragmentTransaction.commit();

toolbar = (Toolbar) findViewById(R.id.toolbar);

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);

ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.app_name, R.string.app_name);
drawer.setDrawerListener(toggle);
toggle.syncState();

navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}

这是最终结果:

enter image description here

请注意,透明工具栏上有一个“边框”。我不知道它来自哪里或如何解决这个问题。

有什么想法吗?

最佳答案

感谢@KeLiuyue 我找到了解决这个问题的方法。

这就是我结束 uo 使用 AppBarLayout 所做的事情:

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:elevation="0dp"
android:stateListAnimator="@null">

关于带有透明工具栏的Android DrawerLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47169761/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com