【问题标题】:ActionBar and title not dissapearing after changes to AndroidManifest.xml and styles.xml in nativescript在 nativescript 中更改 AndroidManifest.xml 和 styles.xml 后,ActionBar 和标题不会消失
【发布时间】:2017-12-22 17:36:02
【问题描述】:

这是我的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.domain.project"
    android:versionCode="1"
    android:versionName="1.0">
<supports-screens
    android:smallScreens="true"
    android:normalScreens="true"
    android:largeScreens="true"
    android:xlargeScreens="true"/>

<uses-sdk
    android:minSdkVersion="17"
    android:targetSdkVersion="25"/>

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:name="com.tns.NativeScriptApplication"
    android:allowBackup="true"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">

    <activity
        android:name="com.tns.NativeScriptActivity"
        android:label="@string/title_activity_kimera"
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:theme="@style/LaunchScreenTheme">

        <meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="com.tns.ErrorReportActivity"/>
</application>
</manifest>

这是我的values/styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- theme to use FOR launch screen-->
    <style name="LaunchScreenThemeBase" parent="Theme.AppCompat.Light.NoActionBar">
        <!--<item name="toolbarStyle">@style/NativeScriptToolbarStyle</item>-->

        <item name="colorPrimary">@color/ns_primary</item>
        <item name="colorPrimaryDark">@color/ns_primaryDark</item>
        <item name="colorAccent">@color/ns_accent</item>

        <item name="android:windowNoTitle">true</item>
        <item name="android:windowActionBar">false</item>
        <item name="android:windowFullscreen">false</item>
        <item name="android:windowContentOverlay">@null</item>

        <item name="android:windowBackground">@drawable/splash_screen</item>

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

    </style>

    <style name="LaunchScreenTheme" parent="LaunchScreenThemeBase">
    </style>

    <!-- theme to use AFTER launch screen is loaded-->
    <style name="AppThemeBase" parent="Theme.AppCompat.Light.NoActionBar">
        <!--<item name="toolbarStyle">@style/NativeScriptToolbarStyle</item>-->

        <item name="colorPrimary">@color/ns_primary</item>
        <item name="colorPrimaryDark">@color/ns_primaryDark</item>
        <item name="colorAccent">@color/ns_accent</item>

        <item name="android:windowNoTitle">true</item>
        <item name="android:windowActionBar">false</item>
        <item name="android:windowFullscreen">false</item>
        <item name="android:windowContentOverlay">@null</item>

    </style>

    <style name="AppTheme" parent="AppThemeBase">
    </style>

    <!-- theme for actioon-bar
    <style name="NativeScriptToolbarStyleBase" parent="Widget.AppCompat.Toolbar">
        <item name="android:background">@color/ns_primary</item>
        <item name="theme">@style/ThemeOverlay.AppCompat.ActionBar</item>
        <item name="popupTheme">@style/ThemeOverlay.AppCompat</item>
    </style>

    <style name="NativeScriptToolbarStyle" parent="NativeScriptToolbarStyleBase">
    </style> -->

</resources> 

我可以根据布尔集更改 android:windowFullscreen 中的值和应用是否全屏显示。所以,我知道 ma​​nifest 文件正在被正确解析。但是,标题栏/操作栏/工具栏根本不会隐藏,并且始终与应用程序一起出现在标题中。

我正在使用这个角种子,不确定是否相关:https://github.com/TeamMaestro/angular-native-seed

我已经被困了一段时间了,有人可以帮忙吗?谢谢:)

【问题讨论】:

  • 检查你的活动类..你是扩展它 AppCompactActivity 还是 Activity ?,你的风格只适用于 AppCompactActivity.....

标签: android xml nativescript


【解决方案1】:

我可以更改 android:windowFullscreen 中的值,然后应用程序运行 全屏与否,取决于布尔集。所以,我知道 清单文件被正确解析。但是,标题栏 / 操作栏/工具栏根本不会隐藏,总是出现 标题中的应用。

您的清单正确,但您的预览设置错误。 您必须记住,Android Studio 预览并不能反映您的应用程序在真实设备上运行时的实际外观。

我创建了一个虚拟项目来解释。这是删除操作栏的代码,类似于您所拥有的:

    android:theme="@style/Theme.AppCompat.Light.NoActionBar">

在源代码中是这样的:

   <style name="Theme.AppCompat.Light.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

现在这清楚地告诉应用不要显示操作栏,就像您的主题一样。但是,如果您查看预览,您会看到:

那么,如何让预览准确反映您的主题?好吧,点击这里:

并调整您的主题以不包含操作栏!

因此,您在预览和应用程序中没有操作栏:

如果这有帮助,请告诉我!

【讨论】:

  • 我通过 ADB 和 USB 连接在真实设备上运行它
【解决方案2】:

我检查了你的代码并没有发现任何问题,但也许代码有问题,但你可以尝试比较适合我的这种风格:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

【讨论】:

    【解决方案3】:

    将此代码添加到style.xml

    <style name="AppTheme.NoActionBar.NoActionBar">
           <item name="windowActionBar">false</item>
           <item name="windowNoTitle">true</item>
    </style>
    

    并将此代码添加到AndroidManifest.xml

    <activity
            android:name="com.tns.NativeScriptActivity"
            android:label="@string/title_activity_kimera"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:theme="@style/AppTheme.NoActionBar.NoActionBar">
    
            <meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />
    
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.tns.ErrorReportActivity"
     android:theme="@style/AppTheme.NoActionBar.NoActionBar"/>
    

    【讨论】:

      【解决方案4】:

      在你的styles.xml中试试这个

      <!-- Base application theme. -->
      <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
          <item name="android:windowNoTitle">true</item>
          <item name="windowActionBar">false</item>
          <!-- Customize your theme here. -->
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-08-08
        • 2017-11-24
        • 2017-11-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多