设置自定义操作栏..
Set a custom action bar..
我想设置一个自定义操作栏,我在下面提供了一张图片..
这个操作栏我想在 android 应用程序中实现,它应该是完全定制的..如何将它设置为片段或者我应该使用 activity 设置..我有点困惑所以请给我建议正确的答案,所以我可以正确地做..
请给我建议答案,以便我可以在我的应用程序中实现它..
正如我在评论中提到的。
<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
作为抽屉。
<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>
我想设置一个自定义操作栏,我在下面提供了一张图片.. 这个操作栏我想在 android 应用程序中实现,它应该是完全定制的..如何将它设置为片段或者我应该使用 activity 设置..我有点困惑所以请给我建议正确的答案,所以我可以正确地做..
请给我建议答案,以便我可以在我的应用程序中实现它..
正如我在评论中提到的。
<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
作为抽屉。
<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>