Author: Adam Pioterek <adam.pioterek@protonmail.ch>
SettingsActivity based on Fragment (looks better)
%!v(PANIC=String method: strings: negative Repeat count)
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6a24bee526d7074fdaf4245f92ed6ffd4a5a6a58..5f4681fca49b83a45a0610ee2e176da39900d4ec 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -33,7 +33,7 @@android:name=".activities.SettingsActivity" android:label="@string/title_activity_settings" android:parentActivityName=".activities.DashActivity" - android:theme="@style/AppTheme.ActionBar" > + android:theme="@style/AppTheme" > <meta-data android:name="android.support.PARENT_ACTIVITY" android:value="ml.adamsprogs.bimba.activities.DashActivity" /> diff --git a/app/src/main/java/ml/adamsprogs/bimba/activities/SettingsActivity.kt b/app/src/main/java/ml/adamsprogs/bimba/activities/SettingsActivity.kt index 90b164cd195ffdb2440443814fc0edc8f801338b..cc70df014cd592d07c7c9dcf553dc13886a552f1 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/activities/SettingsActivity.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/activities/SettingsActivity.kt @@ -2,19 +2,30 @@ package ml.adamsprogs.bimba.activities import android.preference.* import android.os.Bundle +import android.support.v4.app.NavUtils +import android.view.MenuItem +import kotlinx.android.synthetic.main.activity_settings.* import ml.adamsprogs.bimba.* -// todo create layout with toolbar and fragment; and put fragment here class SettingsActivity: AppCompatPreferenceActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + setContentView(R.layout.activity_settings) + setSupportActionBar(toolbar) supportActionBar.setDisplayHomeAsUpEnabled(true) + } - fragmentManager.beginTransaction().replace(android.R.id.content, MainPreferenceFragment()).commit() + override fun onOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + android.R.id.home -> { + NavUtils.navigateUpFromSameTask(this) + return true + } + } + return super.onOptionsItemSelected(item) } - class MainPreferenceFragment : PreferenceFragment() { override fun onCreate(savedInstanceState: Bundle?) { diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml new file mode 100644 index 0000000000000000000000000000000000000000..a989df9974dc26f0fcd10e9d7f0190a99cad86bf --- /dev/null +++ b/app/src/main/res/layout/activity_settings.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="utf-8"?> +<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + xmlns:app="http://schemas.android.com/apk/res-auto"> + + <android.support.design.widget.AppBarLayout + android:id="@+id/appbar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingTop="@dimen/appbar_padding_top" + android:theme="@style/AppTheme.AppBarOverlay" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> + + <android.support.v7.widget.Toolbar + android:id="@+id/toolbar" + android:layout_width="match_parent" + android:layout_height="?attr/actionBarSize" + android:layout_weight="1" + android:background="?attr/colorPrimary" + app:layout_scrollFlags="scroll|enterAlways" + app:popupTheme="@style/AppTheme.PopupOverlay" + app:title="@string/title_activity_settings"> + + </android.support.v7.widget.Toolbar> + </android.support.design.widget.AppBarLayout> + + <fragment + android:id="@+id/settings_fragment" + android:name="ml.adamsprogs.bimba.activities.SettingsActivity$MainPreferenceFragment" + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_marginEnd="8dp" + android:layout_marginStart="8dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/appbar" /> +</android.support.constraint.ConstraintLayout> \ No newline at end of file