Using ActionBar with AppCompat
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Wed, 31 Aug 2016 22:52:11 +0000 (00:52 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Wed, 31 Aug 2016 22:52:11 +0000 (00:52 +0200)
app/src/main/java/name/gumartinm/weather/information/activity/AboutActivity.java
app/src/main/java/name/gumartinm/weather/information/activity/LicensesActivity.java
app/src/main/java/name/gumartinm/weather/information/activity/MainTabsActivity.java
app/src/main/java/name/gumartinm/weather/information/activity/MapActivity.java
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/java/name/gumartinm/weather/information/fragment/specific/SpecificFragment.java
app/src/main/java/name/gumartinm/weather/information/widget/WidgetConfigure.java

index 35fd93e..80d3709 100644 (file)
@@ -29,6 +29,13 @@ public class AboutActivity extends AppCompatActivity {
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+
+        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);
+
         setContentView(R.layout.weather_about);
     }
 
index 8aac5d3..d7dd085 100644 (file)
@@ -38,6 +38,13 @@ public class LicensesActivity extends AppCompatActivity {
     @Override
     public void onCreate(final Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+
+        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);
+
         setContentView(R.layout.weather_licenses);
 
         mWebView = (WebView) this.findViewById(R.id.weather_licenses);
index ccc70a4..5aba1d6 100644 (file)
@@ -59,12 +59,12 @@ public class MainTabsActivity extends AppCompatActivity {
         tabLayout.setupWithViewPager(mPager);
 
         final ActionBar actionBar = this.getSupportActionBar();
-
-        PreferenceManager.setDefaultValues(this, R.xml.weather_preferences, false);
-
-        // Specify that tabs should be displayed in the action bar.
         actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE);
         actionBar.setDisplayHomeAsUpEnabled(true);
+        actionBar.setDisplayShowHomeEnabled(true);
+        actionBar.setIcon(R.drawable.ic_launcher);
+
+        PreferenceManager.setDefaultValues(this, R.xml.weather_preferences, false);
     }
 
     @Override
index 69c8eed..77f4306 100644 (file)
@@ -71,6 +71,13 @@ public class MapActivity extends AppCompatActivity implements
     @Override
     protected void onCreate(final Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+
+        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.setContentView(R.layout.weather_map);
         
         // Acquire a reference to the system Location Manager
index 4d31f15..e7a58c3 100644 (file)
@@ -28,6 +28,12 @@ public class PreferencesActivity extends AppCompatActivity {
     protected void onCreate(final Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
+        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,
index caa0ffe..8189d06 100644 (file)
@@ -34,9 +34,10 @@ public class SpecificActivity extends AppCompatActivity {
         this.setContentView(R.layout.weather_specific);
 
         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);
 
     }
 
index f69e8e2..cb68e4d 100644 (file)
@@ -26,6 +26,7 @@ import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.os.Bundle;
 import android.support.v4.app.Fragment;
+import android.support.v7.app.ActionBar;
 import android.support.v7.app.AppCompatActivity;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -49,6 +50,13 @@ public class SpecificFragment extends Fragment {
     @Override
     public void onCreate(final Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+
+        final AppCompatActivity appCompatActivity = (AppCompatActivity)this.getActivity();
+        final ActionBar actionBar = appCompatActivity.getSupportActionBar();
+        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE);
+        actionBar.setDisplayHomeAsUpEnabled(true);
+        actionBar.setDisplayShowHomeEnabled(true);
+        actionBar.setIcon(R.drawable.ic_launcher);
         
         final Bundle extras = this.getActivity().getIntent().getExtras();
 
index ec8898e..a16a5b4 100644 (file)
@@ -37,6 +37,12 @@ public class WidgetConfigure extends AppCompatActivity {
     public void onCreate(final Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
+        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);
+
         // Find the widget id from the intent. 
         final Intent intent = getIntent();
         final Bundle extras = intent.getExtras();