Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么在所有活动中都添加了“向上”按钮,而我只在一个活动中启用了它?_Java_Android_Debugging_Android Appcompat - Fatal编程技术网

Java 为什么在所有活动中都添加了“向上”按钮,而我只在一个活动中启用了它?

Java 为什么在所有活动中都添加了“向上”按钮,而我只在一个活动中启用了它?,java,android,debugging,android-appcompat,Java,Android,Debugging,Android Appcompat,我按照Google文档添加了up按钮,下面是链接https://developer.android.com/training/implementing-navigation/ancestral?utm_source=udacity&utm_medium=course&utm_campaign=android_basics,因此首先我修改了清单文件,使其看起来像: ?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2016

我按照Google文档添加了up按钮,下面是链接
https://developer.android.com/training/implementing-navigation/ancestral?utm_source=udacity&utm_medium=course&utm_campaign=android_basics
,因此首先我修改了清单文件,使其看起来像:

?xml version="1.0" encoding="utf-8"?><!--
 Copyright (C) 2016 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at
}});}}
          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.

-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.miwok">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name=".PhrasesActivity"
            android:label="@string/category_phrases"
            android:parentActivityName="com.example.android.miwok.MainActivity" />
        <!-- Parent activity meta-data to support 4.0 and lower -->
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.android.miwok.MainActivity" />/>

        <activity android:name=".NumbersActivity"
            android:label="@string/category_numbers"
            android:parentActivityName="com.example.android.miwok.MainActivity" />
        <!-- Parent activity meta-data to support 4.0 and lower -->
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.android.miwok.MainActivity" />/>

        <activity android:name=".FamilyActivity"
            android:label="@string/category_family"
            android:parentActivityName="com.example.android.miwok.MainActivity" />
        <!-- Parent activity meta-data to support 4.0 and lower -->
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.android.miwok.MainActivity" />
        <activity android:name=".ColorsActivity"
            android:label="@string/category_colors"
            android:parentActivityName="com.example.android.miwok.MainActivity" />
        <!-- Parent activity meta-data to support 4.0 and lower -->
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.android.miwok.MainActivity" />/>
    </application>

</manifest>

我无法理解的是,为什么在所有其他子活动中都启用了“向上”按钮,而没有更新它们的java文件???

清单中的这些语句:

    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value="com.example.android.miwok.MainActivity" />

android:parentActivityName="com.example.android.miwok.MainActivity"

我删除了getActionBar()代码行。setDisplayHomeAsUpEnabled(true);而且它仍然有效,所以为什么他们在文档中提到了?提到了,但这不是推荐的方式。给我一分钟编辑我的答案。@Abdell00如果你找到了你想要的答案,请接受这个答案首先谢谢,然后我接受了答案,不过我还有一个问题,那就是android:launchMode=“singleTop”它是返回mainActivity还是仅返回上一个activity?此行只是阻止父activity的重新创建,因此不会再次触发父activity的onCreate()。
    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value="com.example.android.miwok.MainActivity" />

android:parentActivityName="com.example.android.miwok.MainActivity"
android:launchMode="singleTop"