【问题标题】:Remove Padding between hamburger icon and toolbar.?删除汉堡图标和工具栏之间的填充。?
【发布时间】:2017-11-09 16:53:59
【问题描述】:

我在工具栏和汉堡图标之间出现了差距。即使我添加了 app:contentInsetLeftapp:contentInsetStartapp:contentInsetStartWithNavigation ,我仍然得到了差距。

我将以下代码添加到工具栏

<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"
            app:contentInsetLeft="0dp"
            app:contentInsetStart="0dp"
            app:contentInsetStartWithNavigation="0dp"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:background="#fff">
            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
                <TextView
                    android:id="@+id/toolbar_title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Hi, Ajay Jayendran"
                    android:textColor="#123"
                    android:textSize="20sp"
                />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Good Morning"
                    android:textColor="#111"
                    android:layout_below="@+id/toolbar_title"
                    />
            </RelativeLayout>
        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.AppBarLayout>

我使用自己的汉堡图标作为导航抽屉。为此,我使用了以下代码,

toggle.setDrawerIndicatorEnabled(false);
toggle.setHomeAsUpIndicator(R.drawable.navigation_icon);

这里是图标和工具栏之间的截图

有人知道如何缩小汉堡图标和工具栏之间的空间吗?

【问题讨论】:

    标签: android navigation-drawer toolbar


    【解决方案1】:

    试试这个对你有帮助


    <?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="@dimen/_50sp"
        android:fitsSystemWindows="true"
        tools:context="com.HomeActivity">
    
        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="false"
            android:theme="@style/AppTheme.AppBarOverlay">
    
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="wrap_content"
                android:layout_height="@dimen/_50sp"
                android:background="@drawable/top_bar"
                android:weightSum="1"
                app:popupTheme="@style/AppTheme.PopupOverlay"
                app:contentInsetStart="0dp">
    
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1">
    
                    <TextView
                        android:id="@+id/tv_toolBar"
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:layout_centerInParent="true"
                        android:gravity="center"
                        android:paddingRight="@dimen/_60sp"
                        android:text=""
                        android:textAlignment="center"
                        android:textColor="@color/colorWhite"
                        android:textSize="@dimen/toolBar_textSize"
                        android:textStyle="bold" />
    
                    <RelativeLayout
                        android:id="@+id/rl_cartLayout"
                        android:layout_width="@dimen/_50sp"
                        android:layout_height="match_parent"
                        android:layout_alignParentRight="true"
                        android:background="@drawable/cart_bg">
    
                        <RelativeLayout
                            android:id="@+id/iv_cart"
                            android:layout_width="@dimen/_25sp"
                            android:layout_height="@dimen/_25sp"
                            android:layout_centerInParent="true"
                            android:background="@drawable/shop_cart" />
    
                        <RelativeLayout
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_alignParentRight="true"
                            android:layout_marginRight="@dimen/_5sp"
                            android:layout_marginTop="@dimen/_5sp"
                            android:background="@drawable/cart_redbox">
    
                            <TextView
                                android:id="@+id/tvCartItems"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_centerInParent="true"
                                android:background="@null"
                                android:text="0"
                                android:textColor="@color/colorWhite"
                                android:textSize="@dimen/textSize_11sp" />
                        </RelativeLayout>
                    </RelativeLayout>
    
                    <RelativeLayout
                        android:id="@+id/rl_layoutSetting_Back"
                        android:layout_width="@dimen/_50sp"
                        android:layout_height="match_parent"
                        android:background="@drawable/cart_bg"
                        android:visibility="gone">
    
                        <RelativeLayout
                            android:layout_width="@dimen/_25sp"
                            android:layout_height="@dimen/_25sp"
                            android:layout_centerInParent="true"
                            android:background="@drawable/back_icon">
    
                        </RelativeLayout>
                    </RelativeLayout>
                </RelativeLayout>
            </android.support.v7.widget.Toolbar>
        </android.support.design.widget.AppBarLayout>
    </android.support.design.widget.CoordinatorLayout>
    

    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,R.string.navigation_drawer_open, R.string.navigation_drawer_close);
            drawer.setDrawerListener(toggle);
            toggle.setDrawerIndicatorEnabled(false);
            Drawable drawable = ResourcesCompat.getDrawable(getResources(),   R.drawable.top_left_icon,this.getTheme());
            toggle.setHomeAsUpIndicator(drawable);
            toggle.setToolbarNavigationClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (drawer.isDrawerVisible(GravityCompat.START)) {
                        drawer.closeDrawer(GravityCompat.START);
                        isDrawerFromHome=false;
                    } else {
                        isDrawerFromHome=true;
                        drawer.openDrawer(GravityCompat.START);
                    }
                }
            });
            toggle.syncState();
    

    【讨论】:

      【解决方案2】:

      我已经使用了你的代码,现在你可以使用这个 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="?attr/actionBarSize"
                  android:background="?attr/colorPrimary"
                  app:popupTheme="@style/AppTheme.PopupOverlay" >
      
              <RelativeLayout
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content">
                  <TextView
                      android:id="@+id/toolbar_title"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="Hi, Ajay Jayendran"
                      android:textColor="#123"
                      android:textSize="20sp"
                      />
                  <TextView
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="Good Morning"
                      android:textColor="#111"
                      android:layout_below="@+id/toolbar_title"
                      />
              </RelativeLayout>
              </android.support.v7.widget.Toolbar>
          </android.support.design.widget.AppBarLayout>
      

      在java中:-

              setContentView(R.layout.activity_home);
              Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
              setSupportActionBar(toolbar);
      
      
      
              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();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-03-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-24
        • 2016-10-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多