diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ef838e9..655b614 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,7 +7,7 @@ diff --git a/app/src/main/java/com/phantomvk/slideback/demo/BaseActivity.java b/app/src/main/java/com/phantomvk/slideback/demo/BaseActivity.java index e90f8c5..fe112a6 100644 --- a/app/src/main/java/com/phantomvk/slideback/demo/BaseActivity.java +++ b/app/src/main/java/com/phantomvk/slideback/demo/BaseActivity.java @@ -1,5 +1,6 @@ package com.phantomvk.slideback.demo; +import android.annotation.SuppressLint; import android.content.Intent; import android.graphics.Color; import android.os.Build; @@ -7,6 +8,7 @@ import android.view.Window; import android.widget.RadioGroup; +import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.AppCompatButton; import androidx.appcompat.widget.AppCompatTextView; import androidx.appcompat.widget.Toolbar; @@ -28,6 +30,7 @@ * This class contains nothing about {@link SlideActivity}. * Code moved here to make the subclass more easier to read. */ +@SuppressLint("Registered") public class BaseActivity extends SlideActivity { private static int sIndex = 0; @@ -39,6 +42,8 @@ public class BaseActivity extends SlideActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setWindow(); + overridePendingTransition(R.anim.slide_in_right, 0); + setContentView(R.layout.activity_main); } /** @@ -54,8 +59,12 @@ public void onContentChanged() { Toolbar toolbar = findViewById(R.id.toolbar); toolbar.setPadding(0, getStatusBarHeight(), 0, 0); toolbar.setBackgroundColor(mColors[sIndex++ & (8 - 1)]); + setSupportActionBar(toolbar); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); + ActionBar bar = getSupportActionBar(); + if (bar != null) { + bar.setDisplayHomeAsUpEnabled(true); + } AppCompatTextView textView = findViewById(R.id.text); textView.setText(toString().split("\\.")[4]); diff --git a/app/src/main/java/com/phantomvk/slideback/demo/MainActivity.java b/app/src/main/java/com/phantomvk/slideback/demo/MainActivity.java index 1fdedd1..1dcd4f8 100644 --- a/app/src/main/java/com/phantomvk/slideback/demo/MainActivity.java +++ b/app/src/main/java/com/phantomvk/slideback/demo/MainActivity.java @@ -1,18 +1,11 @@ package com.phantomvk.slideback.demo; -import android.os.Bundle; +import android.view.MenuItem; import com.phantomvk.slideback.SlideLayout; public class MainActivity extends BaseActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - overridePendingTransition(R.anim.slide_in_right, 0); - setContentView(R.layout.activity_main); - } - @Override public void onContentChanged() { super.onContentChanged(); @@ -23,6 +16,15 @@ public void onContentChanged() { } } + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == android.R.id.home) { + onBackPressed(); + return true; + } + return super.onOptionsItemSelected(item); + } + @Override public void finishAfterTransition() { SlideLayout l = slideManager.getSlideLayout(); diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index ce4d3d4..78867d9 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -48,23 +48,23 @@ diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml deleted file mode 100644 index aab4c9e..0000000 --- a/app/src/main/res/values/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - SlideBack - diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 1394607..c1142ab 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -11,7 +11,7 @@ @style/toolbarStyle -