gpt4 book ai didi

API 19 上状态栏后面的 Android 工具栏

转载 作者:行者123 更新时间:2023-11-30 01:08:34 24 4
gpt4 key购买 nike

我已经为此苦恼好几天了,还没有找到解决办法。我有一个带有工具栏和几个 fragment 的 NavigationDrawer Activity ,就这么简单。令人费解的是,工具栏仍然位于状态栏之后仅适用于 Android 4.4 (API 19)。

enter image description here

我已经使用了我找到的一切,我什至从另一个运行正常但没有任何改变的应用程序中复制了代码。

这是所有相关代码:

build.gradle

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'realm-android'

android {

compileSdkVersion 24
buildToolsVersion "23.0.3"

defaultConfig {
applicationId "xxx"
minSdkVersion 16
targetSdkVersion 24
versionCode 3
versionName "1.0"
}

signingConfigs {
...
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
debug {
debuggable true
useProguard false
applicationIdSuffix ".debug"
}
}
}

repositories {
mavenCentral()
maven { url "https://jitpack.io" }
maven { url 'https://maven.fabric.io/public' }
maven { url "https://clojars.org/repo/" }
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') {
transitive = true;
}
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:24.1.1'

compile 'com.mcxiaoke.volley:library:1.0.18'

compile 'com.google.android.gms:play-services-gcm:9.2.1'
compile 'com.google.android.gms:play-services-location:9.2.1'
compile 'com.google.android.gms:play-services-maps:9.2.1'

compile 'com.squareup:android-times-square:1.6.5@aar'

compile 'frankiesardo:icepick:3.2.0'
provided 'frankiesardo:icepick-processor:3.2.0'

compile 'com.squareup.picasso:picasso:2.5.2'

compile 'com.jakewharton:butterknife:7.0.1'

compile 'net.danlew:android.joda:2.9.3'

compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1@aar'
}

Android list

<application
android:name=".MyApplication"
android:allowBackup="true"
android:fullBackupContent="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="false"
android:theme="@style/Base.AppTheme">

<activity
android:name=".activity.MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="@style/Base.AppTheme.Main"
android:windowSoftInputMode="stateHidden"/>

</application>

主题.xml

<resources>
<!-- Base -->
<style name="Base.AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primaryColor</item>
<item name="colorPrimaryDark">@color/primaryColor_dark</item>
<item name="colorAccent">@color/accentColor</item>
<item name="android:windowBackground">@color/background_activity</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:fontFamily">sans-serif</item>
</style>

<!-- Main Activity -->
<style name="Base.AppTheme.Main">
<item name="android:textColorSecondary">@android:color/white</item>
</style>
</resources>

activity_main.xml

<?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_drawer_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:background="@color/background_navigationDrawer"
android:fitsSystemWindows="true"
app:itemBackground="@drawable/drawer_item"
app:itemIconTint="@android:color/white"
app:itemTextColor="@android:color/white"
app:menu="@menu/activity_drawer_drawer">

<TextView
android:id="@+id/nav_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:padding="16dp"
android:textColor="@android:color/white"
tools:text="Version 0.0.0"/>
</android.support.design.widget.NavigationView>

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

app_bar_drawer_main.xml

<?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"
tools:context=".activity.MainActivity"
tools:showIn="@layout/activity_main">


<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"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

<TextView
android:id="@+id/toolbar_title"
style="@style/TextView.Toolbar" />

<ImageView
android:id="@+id/toolbar_logo"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:contentDescription="@string/content_desc_logo"
android:padding="12dp"
android:scaleType="fitCenter"
android:src="@drawable/logo_toolbar"
android:visibility="gone" />

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

<android.support.design.widget.TabLayout
android:id="@+id/toolbat_tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:visibility="gone" />

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

<include layout="@layout/content_main" />

<include layout="@layout/component_loading_spinner" />

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

content_main.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
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/main_frame_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".activity.MainActivity"
tools:showIn="@layout/app_bar_drawer_main" />

fragment_browser.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:orientation="vertical">

...

</LinearLayout>
</ScrollView/>

我做错了什么??我必须在 API 19 上做什么才能使 fitSystemWindows 正常工作,以便将 Toolbar 置于状态栏下方?

最佳答案

终于解决了。问题是我覆盖了 styles-v19.xml 中的 themes 并添加了这一行:

<item name="android:windowTranslucentStatus">true</item>

一旦删除它,工具栏就完美了。我将更新样式 fragment 以包含它,以防有人仍然觉得这篇文章有用。

关于API 19 上状态栏后面的 Android 工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38663008/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com