android - 为什么EditText和NavigationIcon之间的宽度不相等

标签 android toolbar

我正在自定义工具栏,但 EditTextNavigationIcon 之间的宽度不相等。

enter image description here

这是我的布局文件。

<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"
android:background="@color/main_header_bg"
android:minHeight="?attr/actionBarSize"
app:titleTextColor="@android:color/white">


   <TextView
       android:id="@+id/tv_title"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_gravity="center"
       android:ellipsize="end"
       android:maxLines="1"
       android:textColor="#333333"
       android:textSize="18sp"
       android:visibility="gone"/>

   <EditText
       android:id="@+id/et_search"
       android:layout_width="match_parent"
       android:layout_height="40dp"
       android:background="@drawable/white_round_bg"
       android:drawableLeft="@drawable/ic_search"
       android:drawablePadding="4dp"
       android:hint="search enjoyours"
       android:padding="4dp"
       android:maxLines="1"
       android:textColorHint="#AEAEAE"
       android:textSize="14sp"
       android:visibility="gone"/>

</android.support.v7.widget.Toolbar>

如何更改 EditText 和 NavigationIcon 之间的宽度(如 EditText 和右侧项目之间的宽度)。

最佳答案

将以下内容添加到您的工具栏

app:contentInsetLeft="0dp" 
app:contentInsetStart="0dp" 
app:contentInsetStartWithNavigation="0dp"

关于android - 为什么EditText和NavigationIcon之间的宽度不相等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41479143/

相关文章:

vim - 删除 GVim 中的工具栏

java - 如何隐藏导航 View android的默认汉堡包图标

java - 如何在Java Swing中使用Label实现 View ?

android - uiautomatorviewer - 错误 : Could not create the Java Virtual Machine

android - 半透明/透明状态栏 + CoordinatorLayout + Toolbar + Fragment

java - Android AndEngine : java. lang.IllegalArgumentException: 未找到 EGLConfig

java - 如何修复Android Studio中的 'Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $'错误

android - 在运行时删除工具栏项目

android - 如何在 android 上调试纯 native 代码?

android - 有没有机会以编程方式将软键盘设置为默认值?