Skip to content

Commit

Permalink
Using custom ids for themes
Browse files Browse the repository at this point in the history
Removed the last change about do not call to base and changed the ids
for themes in style file. Also, created a new style file for api level
21
  • Loading branch information
gonzalonm committed Sep 15, 2016
1 parent 87c4c35 commit 495c32f
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 30 deletions.
40 changes: 20 additions & 20 deletions ApiDemo/App/ActivityRecreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,28 @@ protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);

if (bundle != null) {
current_theme = bundle.GetInt ("theme");
if (bundle != null)
{
current_theme = bundle.GetInt("theme");

switch (current_theme) {
case Android.Resource.Style.ThemeHoloLight:
current_theme = Android.Resource.Style.ThemeHoloDialog;
break;
case Android.Resource.Style.ThemeHoloDialog:
current_theme = Android.Resource.Style.ThemeHolo;
break;
default:
current_theme = Android.Resource.Style.ThemeHoloLight;
break;
}
switch (current_theme)
{
case Resource.Style.ThemeCurrent:
current_theme = Resource.Style.ThemeCurrentDialog;
break;
case Resource.Style.ThemeCurrentDialog:
current_theme = Resource.Style.ThemeCurrentDialogWhenLarge;
break;
case Resource.Style.ThemeCurrentDialogWhenLarge:
current_theme = Resource.Style.Theme;
break;
default:
current_theme = Resource.Style.ThemeCurrent;
break;
}

SetTheme (current_theme);
}
SetTheme(current_theme);
}

SetContentView (Resource.Layout.activity_recreate);

Expand All @@ -60,11 +65,6 @@ protected override void OnCreate (Bundle bundle)
button.Click += delegate { Recreate (); };
}

protected override void OnRestoreInstanceState(Bundle savedInstanceState)
{
// To avoid crash, do not call to base
}

protected override void OnSaveInstanceState (Bundle outState)
{
base.OnSaveInstanceState (outState);
Expand Down
3 changes: 2 additions & 1 deletion ApiDemo/Properties/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
<category android:name="mono.apidemo.sample" />
</intent-filter>
</activity>
<activity android:label="@string/activity_recreate" android:name="monodroid.apidemo.ActivityRecreate" android:enabled="@bool/atLeastHoneycomb">
<activity android:label="@string/activity_recreate" android:name="monodroid.apidemo.ActivityRecreate" android:enabled="@bool/atLeastHoneycomb"
android:theme="@style/Theme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="mono.apidemo.sample" />
Expand Down
12 changes: 6 additions & 6 deletions ApiDemo/Resources/values-v11/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

<resources>
<!-- For API level 11 or later, the Holo theme is available and we prefer that. -->
<style name="ThemeHolo" parent="android:Theme.Holo">
</style>
<style name="ThemeCurrent" parent="android:Theme.Holo"/>

<!-- For API level 11 or later, the Holo theme is available and we prefer that. -->
<style name="ThemeHoloDialog" parent="android:Theme.Holo.Dialog">
</style>
<style name="ThemeCurrentDialog" parent="android:Theme.Holo.Dialog"/>

<!-- For API level 11 or later, we can use the magical DialogWhenLarge theme. -->
<style name="ThemeDialogWhenLarge" parent="android:style/Theme.Holo.DialogWhenLarge">
</style>
<style name="ThemeCurrentDialogWhenLarge" parent="android:style/Theme.Holo.DialogWhenLarge"/>

<!-- For API level 11 or later, the Holo theme is available and we prefer that. -->
<style name="ThemeDefault" parent="@android:style/Theme.Holo" />
</resources>
29 changes: 29 additions & 0 deletions ApiDemo/Resources/values-v21/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 The Android Open Source Project
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.
-->

<resources>
<!-- For API level 21 or later, the Material theme is available and we prefer that. -->
<style name="ThemeCurrent" parent="android:Theme.Material"/>

<!-- For API level 21 or later, the Material theme is available and we prefer that. -->
<style name="ThemeCurrentDialog" parent="android:Theme.Material.Dialog"/>

<!-- For API level 21 or later, we can use the magical DialogWhenLarge theme. -->
<style name="ThemeCurrentDialogWhenLarge" parent="android:style/Theme.Material.DialogWhenLarge"/>

<!-- For API level 21 or later, the Material theme is available and we prefer that. -->
<style name="ThemeDefault" parent="@android:style/Theme.Material" />
</resources>
12 changes: 9 additions & 3 deletions ApiDemo/Resources/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@
The default definition is the safe one, using a theme that has always
been defined. Look at values-11/styles.xml for a variation that is
selected when the holographic theme is available. -->
<style name="ThemeHolo" parent="android:Theme">
<style name="ThemeCurrent" parent="android:Theme">
</style>

<!-- This is a theme that will adjust itself depending on the API version.
The default definition is the safe one, using a theme that has always
been defined. Look at values-11/styles.xml for a variation that is
selected when the holographic theme is available. -->
<style name="ThemeHoloDialog" parent="android:Theme.Dialog">
</style>
<style name="ThemeCurrentDialog" parent="android:Theme.Dialog"/>

<!-- Older platforms don't have Theme.Holo.DialogWhenLarge; we will define
our own wrapper theme that uses it only when running on the appropriate
platform version. On older platforms, we always use the generic
fullscreen theme, because they don't support some feature that help
in correctly laying out an activity as a dialog. -->
<style name="ThemeCurrentDialogWhenLarge" parent="android:style/Theme" />

<!-- Base application theme is the default theme. -->
<style name="Theme" parent="android:Theme">
Expand Down

0 comments on commit 495c32f

Please sign in to comment.