【问题标题】:How to removing space between home (and up) button and title on android action bar?如何在android操作栏上删除主页(和向上)按钮和标题之间的空间?
【发布时间】:2016-07-04 12:56:05
【问题描述】:

在我的应用程序中,我不希望图标和操作栏标题之间​​有多余的空间。 菜单按钮是创建导航活动时的默认按钮。和我带来的后退箭头,包括

 <activity
            android:name=".ShipmentList"
            android:label="Shimpment"
            android:parentActivityName=".MainNavigationActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.mobile.MainNavigationActivity" />
        </activity>

在 AndroidManifest 中。

【问题讨论】:

  • 请把代码放在这里
  • 请同时包含带有app:title的活动xml代码
  • 我也遇到过类似的问题,或许那里的answer可以帮到你:
  • 这发生在我更新到 buildToolsVersion '24.0.2' 之后,如果你不介意将 stepback 降级到 23 就可以了。

标签: android android-actionbar


【解决方案1】:

您必须在工具栏中使用这些行。

app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="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="?actionBarSize"
    android:background="@color/color18"
    android:elevation="0dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark"
    app:contentInsetEnd="0dp"
    app:contentInsetLeft="0dp"
    app:contentInsetRight="0dp"
    app:contentInsetStart="0dp"
    app:contentInsetStartWithNavigation="0dp" />

【讨论】:

  • 后退按钮或主页图标无法同时显示。
【解决方案2】:

在每次版本升级时,我都发现 UI 更改存在一些问题。 这是 android 版本 24 的问题。 它发生在我安装它并将我的构建升级到它时。 也许这是android的新默认设计.. 您可以构建一个工具栏而不是内置的 actionBar,然后您将能够根据需要填充它。 或者,如果您不介意 - 您可以降级到 23.0.3 和 appcompat 23.3.0

*顺便说一句-如果您将降级到 23.0.0 - 23.2.0,您将遇到 colorState = ContextCompat.getColorStateList(ChatActivity.this,R.color.mycolor); 的问题 按钮上的颜色状态更改将无效。

任何方式 - 这是 build.gradle,在 actionBar 的 home 和 title 之间有一个正常的填充:

  apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion '23.0.3'
defaultConfig {
    applicationId "com.xxxxx.xxxxx.xxxx"
    minSdkVersion 19
    targetSdkVersion 23
    versionCode 1
    versionName "1.0.7"
}


buildTypes {
    release {
        shrinkResources true
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
repositories {
    maven {
        url 'https://raw.githubusercontent.com/felixb/mvn-repo/master/'
    }
    mavenCentral()
}
productFlavors {
}
}
 dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:support-annotations:23.3.0'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'   
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多