如何使Android上的工具栏显示完整宽度? [英] How to make toolbar on Android takes a full width?

查看:81
本文介绍了如何使Android上的工具栏显示完整宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

结果如下: http://i.stack.imgur.com/VgbZT. png .我希望它位于状态栏和全角下方,就像这样: http://i.stack.imgur.com/FFQJN.png .

Here is the result: http://i.stack.imgur.com/VgbZT.png. I want it to be right below status bar and full width, just like this one: http://i.stack.imgur.com/FFQJN.png.

<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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MyActivity">

    <!--<android.support.v7.widget.Toolbar-->
        <!--android:id="@+id/toolbar"-->
        <!--android:layout_height="wrap_content"-->
        <!--android:layout_width="match_parent"-->
        <!--android:minHeight="?attr/actionBarSize"-->
        <!--android:background="?attr/colorPrimary" />-->

    <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="wrap_content"
        app:contentInsetEnd="0dp"
        app:contentInsetStart="0dp"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary" >
    </android.support.v7.widget.Toolbar>

</RelativeLayout>

public class MyActivity extends ActionBarActivity {

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

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

我已经阅读了这一个,但仍然无法正常工作.

I already read this one, but it still didn't work.

推荐答案

在根视图上删除padding.

更改:

<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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MyActivity">

    <!--<android.support.v7.widget.Toolbar-->
        <!--android:id="@+id/toolbar"-->
        <!--android:layout_height="wrap_content"-->
        <!--android:layout_width="match_parent"-->
        <!--android:minHeight="?attr/actionBarSize"-->
        <!--android:background="?attr/colorPrimary" />-->

    <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="wrap_content"
        app:contentInsetEnd="0dp"
        app:contentInsetStart="0dp"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary" >
    </android.support.v7.widget.Toolbar>

</RelativeLayout>

收件人:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
    android:layout_height="match_parent" 
    tools:context=".MyActivity">

    <!--<android.support.v7.widget.Toolbar-->
        <!--android:id="@+id/toolbar"-->
        <!--android:layout_height="wrap_content"-->
        <!--android:layout_width="match_parent"-->
        <!--android:minHeight="?attr/actionBarSize"-->
        <!--android:background="?attr/colorPrimary" />-->

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:contentInsetEnd="0dp"
        app:contentInsetStart="0dp"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary" >
    </android.support.v7.widget.Toolbar>

</RelativeLayout>

这篇关于如何使Android上的工具栏显示完整宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆