设置自定义操作栏..

时间:2018-02-19 07:00:35

标签: android design-patterns android-actionbar custom-action

我想设置一个自定义操作栏,我提供下面的图片.. 这个动作栏我想在Android应用程序中实现,它应该是完全自定义..如何将其设置为片段或我应该设置使用活动..我有点困惑所以请建议我正确的答案,所以我可以正确..

enter image description here

请建议我的答案,以便我可以在我的应用程序中实现它。

2 个答案:

答案 0 :(得分:1)

   <android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    app:elevation="0dp"
    android:background="@drawable/custum_background_toolbar"
    android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
    android:layout_width="match_parent"
    android:layout_height="@dimen/action_bar_height"
    android:layout_gravity="top"
    android:layout_marginLeft="@dimen/button_margin"
    android:layout_marginRight="@dimen/button_margin"
    android:layout_marginBottom="@dimen/button_margin"
    android:background="@drawable/custum_button_red_background"
    app:titleTextColor="@color/white">

    <RelativeLayout
        android:layout_width="match_parent"
        android:gravity="center_vertical"
        android:layout_height="match_parent">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_gravity="start"
        android:id="@+id/leftArrowContacts"
        android:layout_alignParentStart="true"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/ic_keyboard_backspace_white_24dp"
        android:layout_alignParentLeft="true" />
    <TextView
        android:layout_width="wrap_content"
        android:text="@string/anouncer_list"
        android:layout_marginLeft="@dimen/_25sdp"
        android:layout_alignParentStart="true"
        android:textColor="@color/white"
        android:textSize="@dimen/_14sdp"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true" />
        <ImageView
            android:id="@+id/add_contacts"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_marginRight="@dimen/_10sdp"
            app:srcCompat="@drawable/ic_add_white_24dp"/>
    </RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>

答案 1 :(得分:0)

正如我在评论中提到的那样。

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                android:gravity="center"
                app:popupTheme="@style/AppTheme.PopupOverlay">

                <TextView
                    android:id="@+id/toolbar_title"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center"
                    android:gravity="center"
                    android:textColor="@color/white"
                    android:textSize="@dimen/header_text"
                    android:text="Title"

                    />


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

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

设置工具栏。

  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  TextView toolbarTitleTxt = (TextView) findViewById(R.id.toolbar_title);
  setSupportActionBar(toolbar);
  getSupportActionBar().setTitle("");
  toolbarTitleTxt.setText("Title")

MenuItems增加一个菜单,并使用DrawerLayout作为抽屉。

相关问题