Skip to content

Commit 7bd1eeb

Browse files
committed
Switched from using ActionBar to using Toolbar
1 parent 3ef2dfa commit 7bd1eeb

File tree

8 files changed

+107
-49
lines changed

8 files changed

+107
-49
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ android {
2222
dependencies {
2323
compile fileTree(dir: 'libs', include: ['*.jar'])
2424
compile 'com.github.bumptech.glide:glide:3.5.2'
25-
compile 'com.android.support:appcompat-v7:21.0.2'
26-
compile 'com.android.support:support-annotations:22.0.0'
25+
compile 'com.android.support:appcompat-v7:22.1.0'
26+
compile 'com.android.support:support-annotations:22.1.0'
2727
compile 'com.google.android.gms:play-services-gcm:7.0.0'
2828
}

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@
4343
android:supportsRtl="true">
4444
<activity
4545
android:name=".MainActivity"
46-
android:label="@string/app_name"
47-
android:theme="@style/ForecastTheme" >
46+
android:label="@string/app_name">
4847
<intent-filter>
4948
<action android:name="android.intent.action.MAIN" />
5049

app/src/main/java/com/example/android/sunshine/app/DetailActivity.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,23 @@
1818
import android.content.Intent;
1919
import android.os.Bundle;
2020
import android.support.v7.app.ActionBarActivity;
21+
import android.support.v7.app.AppCompatActivity;
22+
import android.support.v7.widget.Toolbar;
2123
import android.view.Menu;
2224
import android.view.MenuItem;
2325

2426

25-
public class DetailActivity extends ActionBarActivity {
27+
public class DetailActivity extends AppCompatActivity {
2628

2729
@Override
2830
protected void onCreate(Bundle savedInstanceState) {
2931
super.onCreate(savedInstanceState);
3032
setContentView(R.layout.activity_detail);
3133

34+
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
35+
setSupportActionBar(toolbar);
36+
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
37+
3238
if (savedInstanceState == null) {
3339
// Create the detail fragment and add it to the activity
3440
// using a fragment transaction.

app/src/main/java/com/example/android/sunshine/app/MainActivity.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
import android.net.Uri;
2525
import android.os.AsyncTask;
2626
import android.os.Bundle;
27-
import android.support.v7.app.ActionBarActivity;
27+
import android.support.v7.app.AppCompatActivity;
28+
import android.support.v7.widget.Toolbar;
2829
import android.util.Log;
2930
import android.view.Menu;
3031
import android.view.MenuItem;
@@ -36,7 +37,7 @@
3637

3738
import java.io.IOException;
3839

39-
public class MainActivity extends ActionBarActivity implements ForecastFragment.Callback {
40+
public class MainActivity extends AppCompatActivity implements ForecastFragment.Callback {
4041

4142
private final String LOG_TAG = MainActivity.class.getSimpleName();
4243
private static final String DETAILFRAGMENT_TAG = "DFTAG";
@@ -60,6 +61,10 @@ protected void onCreate(Bundle savedInstanceState) {
6061
mLocation = Utility.getPreferredLocation(this);
6162

6263
setContentView(R.layout.activity_main);
64+
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
65+
setSupportActionBar(toolbar);
66+
getSupportActionBar().setDisplayShowTitleEnabled(false);
67+
6368
if (findViewById(R.id.weather_detail_container) != null) {
6469
// The detail container view will be present only in the large-screen layouts
6570
// (res/layout-sw600dp). If this view is present, then the activity should be

app/src/main/res/layout-sw600dp/activity_main.xml

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,46 @@
1717
xmlns:tools="http://schemas.android.com/tools"
1818
android:layout_width="match_parent"
1919
android:layout_height="match_parent"
20-
android:baselineAligned="false"
21-
android:divider="?android:attr/dividerHorizontal"
22-
android:orientation="horizontal"
23-
tools:context="com.example.android.sunshine.app.MainActivity">
24-
25-
<!--
26-
This layout is a two-pane layout for the Items master/detail flow.
27-
-->
28-
29-
<fragment
30-
android:id="@+id/fragment_forecast"
31-
android:name="com.example.android.sunshine.app.ForecastFragment"
32-
android:layout_width="0dp"
33-
android:layout_height="match_parent"
34-
android:layout_weight="2"
35-
tools:layout="@android:layout/list_content" />
20+
android:orientation="vertical">
21+
22+
<android.support.v7.widget.Toolbar
23+
android:id="@+id/toolbar"
24+
android:layout_width="match_parent"
25+
android:layout_height="?attr/actionBarSize"
26+
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
27+
>
28+
<ImageView
29+
android:layout_width="wrap_content"
30+
android:layout_height="match_parent"
31+
android:src="@drawable/ic_logo"
32+
android:scaleType="center"/>
33+
</android.support.v7.widget.Toolbar>
3634

37-
<FrameLayout
38-
android:id="@+id/weather_detail_container"
39-
android:layout_width="0dp"
35+
<LinearLayout
36+
android:layout_width="match_parent"
4037
android:layout_height="match_parent"
41-
android:layout_weight="4" />
38+
android:baselineAligned="false"
39+
android:divider="?android:attr/dividerHorizontal"
40+
android:orientation="horizontal"
41+
tools:context="com.example.android.sunshine.app.MainActivity">
42+
43+
<!--
44+
This layout is a two-pane layout for the Items master/detail flow.
45+
-->
46+
47+
<fragment
48+
android:id="@+id/fragment_forecast"
49+
android:name="com.example.android.sunshine.app.ForecastFragment"
50+
android:layout_width="0dp"
51+
android:layout_height="match_parent"
52+
android:layout_weight="2"
53+
tools:layout="@android:layout/list_content" />
54+
55+
<FrameLayout
56+
android:id="@+id/weather_detail_container"
57+
android:layout_width="0dp"
58+
android:layout_height="match_parent"
59+
android:layout_weight="4" />
4260

43-
</LinearLayout>
61+
</LinearLayout>
62+
</LinearLayout>

app/src/main/res/layout/activity_detail.xml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,23 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
-->
16-
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
17-
xmlns:tools="http://schemas.android.com/tools"
18-
android:id="@+id/weather_detail_container"
16+
<LinearLayout
17+
xmlns:android="http://schemas.android.com/apk/res/android"
1918
android:layout_width="match_parent"
20-
android:layout_height="match_parent"
21-
tools:context="com.example.android.sunshine.app.DetailActivity"
22-
tools:ignore="MergeRootFrame" />
19+
android:layout_height="wrap_content"
20+
android:orientation="vertical">
21+
22+
<android.support.v7.widget.Toolbar
23+
android:id="@+id/toolbar"
24+
android:layout_width="match_parent"
25+
android:layout_height="?attr/actionBarSize"
26+
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
27+
28+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
29+
xmlns:tools="http://schemas.android.com/tools"
30+
android:id="@+id/weather_detail_container"
31+
android:layout_width="match_parent"
32+
android:layout_height="match_parent"
33+
tools:context="com.example.android.sunshine.app.DetailActivity"
34+
tools:ignore="MergeRootFrame" />
35+
</LinearLayout>

app/src/main/res/layout/activity_main.xml

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,30 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
-->
16-
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
16+
<LinearLayout
17+
xmlns:android="http://schemas.android.com/apk/res/android"
1718
xmlns:tools="http://schemas.android.com/tools"
18-
android:id="@+id/fragment_forecast"
19-
android:name="com.example.android.sunshine.app.ForecastFragment"
2019
android:layout_width="match_parent"
21-
android:layout_height="match_parent"
22-
tools:context="com.example.android.sunshine.app.ForecastFragment"
23-
tools:layout="@android:layout/list_content" />
20+
android:layout_height="wrap_content"
21+
android:orientation="vertical">
22+
23+
<android.support.v7.widget.Toolbar
24+
android:id="@+id/toolbar"
25+
android:layout_width="match_parent"
26+
android:layout_height="?attr/actionBarSize"
27+
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
28+
<ImageView
29+
android:layout_width="wrap_content"
30+
android:layout_height="match_parent"
31+
android:src="@drawable/ic_logo"
32+
android:scaleType="center"/>
33+
</android.support.v7.widget.Toolbar>
34+
35+
<fragment
36+
android:id="@+id/fragment_forecast"
37+
android:name="com.example.android.sunshine.app.ForecastFragment"
38+
android:layout_width="match_parent"
39+
android:layout_height="match_parent"
40+
tools:context="com.example.android.sunshine.app.ForecastFragment"
41+
tools:layout="@android:layout/list_content" />
42+
</LinearLayout>

app/src/main/res/values/styles.xml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,22 @@
1616
<resources>
1717

1818
<!-- Base application theme. -->
19-
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
19+
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
2020
<item name="colorPrimary">@color/primary</item>
2121
<item name="colorPrimaryDark">@color/primary_dark</item>
2222
<item name="colorAccent">@color/accent</item>
23+
<item name="toolbarStyle">@style/Toolbar</item>
2324
</style>
2425

25-
<!-- Main activity theme. -->
26-
<style name="ForecastTheme" parent="AppTheme">
27-
<item name="actionBarStyle">@style/ActionBar.Solid.Sunshine.NoTitle</item>
28-
</style>
2926

3027
<!-- Settings activity theme. -->
3128
<style name="SettingsTheme" parent="AppTheme">
3229
</style>
3330

34-
<!-- main activity action bar styles -->
35-
<style name="ActionBar.Solid.Sunshine.NoTitle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
36-
<item name="displayOptions">useLogo|showHome</item>
37-
<item name="logo">@drawable/ic_logo</item>
31+
<!-- main activity toolbar style -->
32+
<style name="Toolbar" parent="Widget.AppCompat.Toolbar">
33+
<item name="android:background">?attr/colorPrimary</item>
34+
<item name="popupTheme">@style/Theme.AppCompat.Light</item>
3835
</style>
3936

4037
<!-- Style for forecast listview -->

0 commit comments

Comments
 (0)