首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >设计自定义导航栏

设计自定义导航栏
EN

Stack Overflow用户
提问于 2019-11-27 00:39:46
回答 1查看 255关注 0票数 0

目前,我正在尝试使一个自定义导航栏,如给出的图像。

我创建这个导航栏的代码现在看起来像这样:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>


<android.support.constraint.ConstraintLayout 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/nav"
    android:layout_width="match_parent"
    android:layout_height="110dp"
    android:background="@android:color/transparent"
    android:orientation="vertical">

    <View
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:alpha="0.8"
        android:background="#0089BA"
        app:layout_constraintBottom_toBottomOf="@+id/linearLayout3"
        app:layout_constraintEnd_toEndOf="parent"></View>


    <LinearLayout
        android:id="@+id/linearLayout3"
        android:layout_width="match_parent"
        android:layout_height="110dp"
        android:background="@android:color/transparent"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_centerHorizontal="true"
            android:gravity="center_horizontal"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <android.support.design.widget.FloatingActionButton
                android:id="@+id/floatingActionButton"
                android:layout_width="100dp"
                android:layout_height="70"
                android:layout_gravity="center_horizontal"
                android:layout_weight="1"
                android:clickable="true"
                app:srcCompat="@drawable/common_google_signin_btn_icon_dark" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/linearLayout2"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="#0089BA"
            android:orientation="horizontal"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <ImageView
                android:id="@+id/home_img"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_weight="1"
                app:srcCompat="@drawable/googleg_standard_color_18" />

            <ImageView
                android:id="@+id/home_img2"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_weight="1"
                app:srcCompat="@drawable/googleg_standard_color_18" />

            <ImageView
                android:id="@+id/home_img3"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_weight="1"
                app:srcCompat="@drawable/googleg_standard_color_18" />

            <ImageView
                android:id="@+id/home_img4"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_weight="1"
                app:srcCompat="@drawable/googleg_standard_color_18" />
        </LinearLayout>

    </LinearLayout>


</android.support.constraint.ConstraintLayout>

但是因为我真的不擅长用xml进行设计,所以我希望能得到一些帮助。如何实现这种设计,以及如何更好地使用xml进行设计?Color:#0089BA透明度: 80 %我正在使用相同的谷歌图标来测试这个设计。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-27 01:01:28

我推荐使用底部导航视图。声明该对象将如下所示

代码语言:javascript
复制
<android.support.design.widget.BottomNavigationView
    android:id="@+id/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="56dp"
    android:layout_gravity="start"
    android:layout_alignParentBottom="true"
    android:background="@android:color/white"
    app:elevation="16dp"
    app:menu="@menu/bottom_navigation_main" /> 

和bottom_navigation_main:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<menu
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/menu_1"
        android:enabled="true"
        android:icon="@drawable/someImage"
        android:title="@string/tab1_title"
        app:showAsAction="ifRoom" />
    <item
        android:id="@+id/menu_1"
        android:enabled="true"
        android:icon="@drawable/someImage"
        android:title="@string/tab2_title"
        app:showAsAction="ifRoom" />
</menu>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59055594

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档