AppCompatActivity onBackPressed() -Methode kann nicht in meiner Aktivität ausgelöst werden.onBackPressed() - Methode in AppCompatActivity nicht ausgelöst
Ich sehe die Zurück-Pfeil-Taste und bekomme die Animation beim Drücken, aber sonst passiert nichts. Das Überschreiben von onKeyDown() hat den gleichen Effekt. es heißt nicht.
Ich habe viele Stunden damit verbracht, dies ohne Glück zu erforschen. Nichts scheint zu funktionieren. Jeder hat ein ähnliches Problem gehabt? Vielleicht ist das ein bekannter Bug?
Mein Activity.xml:
<RelativeLayout 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" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.litenote.android.BackTestingActivity2Activity">
<include
android:id="@+id/appBar"
layout="@layout/app_bar" />
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
app_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/primary"
android:titleTextAppearance="@color/textWhite"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
android:popupTheme="@style/CustomPopupMenuTheme">
Die Aktivität Java-Datei
package com.litenote.android;
import android.support.v7.app.ActionBar;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import com.superpad.android.R;
public class BackTestingActivity2Activity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_back_testing_activity2);
Toolbar actionBar = ((Toolbar) findViewById(R.id.appBar));
setSupportActionBar(actionBar);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
@Override
public void onBackPressed() {
Log.d("BACK_BUTTON_DOESNT_WORK", "I will never execute and you will never see me :(");
super.onBackPressed();
this.finish();
}
}
Fang zurück-Taste auf Schlüsselmethode klicken, und rufen 'onBackPressed()' –
Wenn ich meine Aktivität onKeyDown() außer Kraft setzen, dass doesn Ich werde auch nicht angerufen, obwohl die Taste gedrückt ist und ich sie drücken kann. –
Welcher Pfeil ist das? 'onBackPressed' ist für die physische Zurück-Schaltfläche neben der Home-Schaltfläche. – njzk2