android - 如何删除操作栏中 Logo 左侧的填充?

标签 android android-layout android-studio

我的 Activity

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <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"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

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

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

我的 Mainfest 文件

<activity
    android:theme="@style/AppTheme.NoActionBar"
    android:windowSoftInputMode="adjustResize|stateAlwaysHidden">
    <intent-filter>

        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

我尝试了很多东西,但似乎没有任何效果,这就是我上传这个问题的原因。我删除了填充,甚至尝试了 contentInsets,但没有任何效果。

I want to remove that yellow space

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_navigate);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        toolbar.setLogo(R.drawable.ic_account_circle_black);

 DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
}
}

抽屉布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    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/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_navigation_to_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_navigation_to_main"
        app:menu="@menu/activity_navigation_to_main_drawer" />

</android.support.v4.widget.DrawerLayout>

最佳答案

您可以使用内容插入功能。 左侧插图是由 Toolbar 的 contentInsetStart 引起的,默认情况下为 16dp。

试试这个

<android.support.v7.widget.Toolbar
    xmlns:app="schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/primaryColor"
    app:contentInsetLeft="0dp"
    app:contentInsetStart="0dp"
    app:contentInsetRight="0dp"
    app:contentInsetEnd="0dp" />

并将其添加到您的根目录。

xmlns:app="schemas.android.com/apk/res-auto"; 

在你的安卓代码中试试这个

Toolbar.setContentInsetStartWithNavigation(0);

在最坏的情况下试试这个。 在您的 onCreate Activity 中添加以下代码。

ImageView view = (ImageView)findViewById(android.R.id.home);
view.setPadding(10, 0, 0, 0);

让我知道它是否有效。

关于android - 如何删除操作栏中 Logo 左侧的填充?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39741258/

相关文章:

android studio 2.2.3设计页面

android - 我可以通过编程方式从我的 GridView 制作可点击的项目吗?

java - 如何在将在 RecyclerView 中添加卡片的 fragment 中设置 OnclickListener FAB

android - ListView 不显示任何内容并隐藏数据

android:layout_width 以及布局权重使用

javascript - Android Studio 无法获取调用按钮

android-studio - 为什么三星 Galaxy S10 Plus 皮肤在 Android Studio 中看起来很奇怪?

android - 将 Android Studio 调试崩溃排除在 Google Play 开发者控制台之外?

c# - 如何使用 Xamarin.Android 在相机流上绘制标记?

java - 如何确定哪个用户正在从 Android 应用程序发出 Rest 请求?