Using ToolBar in PreferencesActivity and SpecificActivity
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 4 Sep 2016 01:58:45 +0000 (03:58 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 4 Sep 2016 01:58:45 +0000 (03:58 +0200)
app/src/main/java/name/gumartinm/weather/information/activity/PreferencesActivity.java
app/src/main/java/name/gumartinm/weather/information/activity/SpecificActivity.java
app/src/main/res/layout/weather_preferences.xml [new file with mode: 0644]
app/src/main/res/layout/weather_specific.xml

index e7a58c3..6754a68 100644 (file)
@@ -18,26 +18,24 @@ package name.gumartinm.weather.information.activity;
 import android.os.Bundle;
 import android.support.v7.app.ActionBar;
 import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.Toolbar;
 
 import name.gumartinm.weather.information.R;
-import name.gumartinm.weather.information.fragment.preferences.PreferencesFragment;
 
 public class PreferencesActivity extends AppCompatActivity {
 
     @Override
     protected void onCreate(final Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+        this.setContentView(R.layout.weather_preferences);
+
+        final Toolbar toolbar = (Toolbar) findViewById(R.id.weather_main_toolbar);
+        this.setSupportActionBar(toolbar);
 
         final ActionBar actionBar = this.getSupportActionBar();
-        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE);
         actionBar.setDisplayHomeAsUpEnabled(true);
         actionBar.setDisplayShowHomeEnabled(true);
         actionBar.setIcon(R.drawable.ic_launcher);
-
-        this.getFragmentManager()
-        .beginTransaction()
-        .replace(android.R.id.content,
-                new PreferencesFragment()).commit();
     }
 
     @Override
index be25b0e..b6dc05d 100644 (file)
@@ -18,6 +18,7 @@ package name.gumartinm.weather.information.activity;
 import android.os.Bundle;
 import android.support.v7.app.ActionBar;
 import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.Toolbar;
 
 import java.text.MessageFormat;
 import java.util.Locale;
@@ -33,8 +34,10 @@ public class SpecificActivity extends AppCompatActivity {
         super.onCreate(savedInstanceState);
         this.setContentView(R.layout.weather_specific);
 
+        final Toolbar toolbar = (Toolbar) findViewById(R.id.weather_main_toolbar);
+        this.setSupportActionBar(toolbar);
+
         final ActionBar actionBar = this.getSupportActionBar();
-        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE);
         actionBar.setDisplayHomeAsUpEnabled(true);
         actionBar.setDisplayShowHomeEnabled(true);
         actionBar.setIcon(R.drawable.ic_launcher);
diff --git a/app/src/main/res/layout/weather_preferences.xml b/app/src/main/res/layout/weather_preferences.xml
new file mode 100644 (file)
index 0000000..c311702
--- /dev/null
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright 2016 Gustavo Martin Morcuende
+
+    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.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:id="@+id/weather_specific"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:gravity="center"
+    android:orientation="vertical"
+    tools:context="name.gumartinm.weather.information.activity.PreferencesActivity"
+    tools:ignore="MergeRootFrame" >
+
+    <include layout="@layout/weather_general_toolbar"/>
+
+    <fragment
+        android:id="@+id/specific_fragment"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        class="name.gumartinm.weather.information.fragment.preferences.PreferencesFragment" />
+
+</LinearLayout>
\ No newline at end of file
index 7147a21..11c2d22 100644 (file)
@@ -24,6 +24,7 @@
     tools:context="name.gumartinm.weather.information.activity.SpecificActivity"
     tools:ignore="MergeRootFrame" >
 
+     <include layout="@layout/weather_general_toolbar"/>
 
      <fragment
         android:id="@+id/specific_fragment"