答案 0 :(得分:2)
为此使用Toolbar
,它将提供更好的自定义。
以下是示例示例。
<强> toolbar.xml 强>
<?xml version="1.0" encoding="utf-8"?>
<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="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways"
app:layout_collapseMode="pin">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- This is a centered logo -->
<ImageView
android:id="@+id/toolbar_logo"
android:src="@drawable/logo"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="?attr/actionBarSize"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:layout_gravity="center" />
<!-- This is a centered title -->
<!--
<TextView
android:id="@+id/toolbar_title"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="?attr/actionBarSize"
android:layout_gravity="center"
android:gravity="center_vertical"
android:visibility="gone"
android:text="@string/app_name"
android:textColor="@color/white"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse"
/>
-->
<!-- This is a custom left side button -->
<!--
<ImageButton
android:id="@+id/btn_settings"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:layout_marginRight="?attr/actionBarSize"
android:layout_gravity="start|center_vertical"
android:visibility="invisible"
android:src="@drawable/ic_settings_white_24dp"
style="@style/Widget.AppCompat.ActionButton" />
-->
<!-- This is a custom right side button -->
<!--
<ImageButton
android:id="@+id/btn_search"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="end"
android:src="@drawable/ic_magnify_white_24dp"
style="@style/Widget.AppCompat.ActionButton" />
-->
</FrameLayout>
</android.support.v7.widget.Toolbar>
在工具栏中添加任何视图,因为它是一个视图组。这有助于
答案 1 :(得分:0)
使用此
getActionBar().setDisplayHomeAsUpEnabled(false)
答案 2 :(得分:0)
试试这个
import pandas
import numpy
numpy.random.seed(1)
cols = ['my_buy_price', 'global_buy_price', 'global_middle_price', 'global_sell_price']
df = pandas.DataFrame(index = range(10), columns=cols)
df['global_buy_price'] = 400
df['global_sell_price'] = 500
df['global_middle_price'] = df[['global_buy_price', 'global_sell_price']].mean(axis=1)
df['my_buy_price'] = [numpy.random.randint(350, 550) for x in range(len(df))]
df['I bought'] = '?'
print(df)
header_with_back.xml代码
<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="?android:attr/actionBarSize"
android:supportsRtl="false"
app:popupTheme="@style/AppTheme.PopupOverlay">
<include layout="@layout/header_with_back"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
Java代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="@color/colorPrimary"
android:orientation="vertical">
<ImageView
android:id="@+id/image_back_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/threedp"
android:padding="@dimen/tendp"
android:layout_marginRight="-20dp"
android:src="@drawable/ic_arrow_back_black_24dp"/>
<TextView
android:id="@+id/txt_title_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/image_back_header"
android:layout_centerVertical="true"
android:ellipsize="end"
android:paddingTop="@dimen/tendp"
android:paddingBottom="@dimen/tendp"
android:layout_marginLeft="@dimen/twentydp"
android:maxLength="26"
android:text="dsdsdsa"
android:gravity="center"
android:maxLines="1"
android:textColor="@color/white"
android:textSize="@dimen/text_18"
android:typeface="normal"/>
<TextView
android:id="@+id/txt_right_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:ellipsize="none"
android:gravity="center"
android:maxLines="1"
android:textColor="@color/white"
android:textSize="@dimen/text_16"
android:layout_alignParentRight="true"
android:paddingTop="@dimen/tendp"
android:paddingBottom="@dimen/tendp"
android:paddingLeft="@dimen/tendp"
android:paddingRight="@dimen/fifteendp"
android:text="@string/save"
android:typeface="normal"/>
</RelativeLayout>
答案 3 :(得分:0)
尝试将这些属性添加到toolBar
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
最终工具栏应该是这样的
<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="?attr/actionBarSize"
android:background="@drawable/paper9patch"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
/>