Switched from using ActionBar to using Toolbar

This commit is contained in:
Dan Galpin
2015-05-25 01:29:03 -07:00
parent 3ef2dfaea6
commit 7bd1eeb1e6
8 changed files with 105 additions and 47 deletions

View File

@@ -22,7 +22,7 @@ android {
dependencies { dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.github.bumptech.glide:glide:3.5.2' compile 'com.github.bumptech.glide:glide:3.5.2'
compile 'com.android.support:appcompat-v7:21.0.2' compile 'com.android.support:appcompat-v7:22.1.0'
compile 'com.android.support:support-annotations:22.0.0' compile 'com.android.support:support-annotations:22.1.0'
compile 'com.google.android.gms:play-services-gcm:7.0.0' compile 'com.google.android.gms:play-services-gcm:7.0.0'
} }

View File

@@ -43,8 +43,7 @@
android:supportsRtl="true"> android:supportsRtl="true">
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:label="@string/app_name" android:label="@string/app_name">
android:theme="@style/ForecastTheme" >
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />

View File

@@ -18,17 +18,23 @@ package com.example.android.sunshine.app;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
public class DetailActivity extends ActionBarActivity { public class DetailActivity extends AppCompatActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail); setContentView(R.layout.activity_detail);
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (savedInstanceState == null) { if (savedInstanceState == null) {
// Create the detail fragment and add it to the activity // Create the detail fragment and add it to the activity
// using a fragment transaction. // using a fragment transaction.

View File

@@ -24,7 +24,8 @@ import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@@ -36,7 +37,7 @@ import com.google.android.gms.gcm.GoogleCloudMessaging;
import java.io.IOException; import java.io.IOException;
public class MainActivity extends ActionBarActivity implements ForecastFragment.Callback { public class MainActivity extends AppCompatActivity implements ForecastFragment.Callback {
private final String LOG_TAG = MainActivity.class.getSimpleName(); private final String LOG_TAG = MainActivity.class.getSimpleName();
private static final String DETAILFRAGMENT_TAG = "DFTAG"; private static final String DETAILFRAGMENT_TAG = "DFTAG";
@@ -60,6 +61,10 @@ public class MainActivity extends ActionBarActivity implements ForecastFragment.
mLocation = Utility.getPreferredLocation(this); mLocation = Utility.getPreferredLocation(this);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
if (findViewById(R.id.weather_detail_container) != null) { if (findViewById(R.id.weather_detail_container) != null) {
// The detail container view will be present only in the large-screen layouts // The detail container view will be present only in the large-screen layouts
// (res/layout-sw600dp). If this view is present, then the activity should be // (res/layout-sw600dp). If this view is present, then the activity should be

View File

@@ -15,6 +15,24 @@
--> -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_logo"
android:scaleType="center"/>
</android.support.v7.widget.Toolbar>
<LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:baselineAligned="false" android:baselineAligned="false"
@@ -40,4 +58,5 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="4" /> android:layout_weight="4" />
</LinearLayout>
</LinearLayout> </LinearLayout>

View File

@@ -13,10 +13,23 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/weather_detail_container" android:id="@+id/weather_detail_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context="com.example.android.sunshine.app.DetailActivity" tools:context="com.example.android.sunshine.app.DetailActivity"
tools:ignore="MergeRootFrame" /> tools:ignore="MergeRootFrame" />
</LinearLayout>

View File

@@ -13,11 +13,30 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<fragment xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_logo"
android:scaleType="center"/>
</android.support.v7.widget.Toolbar>
<fragment
android:id="@+id/fragment_forecast" android:id="@+id/fragment_forecast"
android:name="com.example.android.sunshine.app.ForecastFragment" android:name="com.example.android.sunshine.app.ForecastFragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context="com.example.android.sunshine.app.ForecastFragment" tools:context="com.example.android.sunshine.app.ForecastFragment"
tools:layout="@android:layout/list_content" /> tools:layout="@android:layout/list_content" />
</LinearLayout>

View File

@@ -16,25 +16,22 @@
<resources> <resources>
<!-- Base application theme. --> <!-- Base application theme. -->
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar"> <style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primary</item> <item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item> <item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item> <item name="colorAccent">@color/accent</item>
<item name="toolbarStyle">@style/Toolbar</item>
</style> </style>
<!-- Main activity theme. -->
<style name="ForecastTheme" parent="AppTheme">
<item name="actionBarStyle">@style/ActionBar.Solid.Sunshine.NoTitle</item>
</style>
<!-- Settings activity theme. --> <!-- Settings activity theme. -->
<style name="SettingsTheme" parent="AppTheme"> <style name="SettingsTheme" parent="AppTheme">
</style> </style>
<!-- main activity action bar styles --> <!-- main activity toolbar style -->
<style name="ActionBar.Solid.Sunshine.NoTitle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"> <style name="Toolbar" parent="Widget.AppCompat.Toolbar">
<item name="displayOptions">useLogo|showHome</item> <item name="android:background">?attr/colorPrimary</item>
<item name="logo">@drawable/ic_logo</item> <item name="popupTheme">@style/Theme.AppCompat.Light</item>
</style> </style>
<!-- Style for forecast listview --> <!-- Style for forecast listview -->