LoginSignup
19
18

More than 5 years have passed since last update.

Xamarin.Android Theme 記述方法について

Last updated at Posted at 2014-10-15

こんにちは。エクセルソフトの田淵です。

Android の Activity に Style を参照させたり、直接 Theme を指定したり、良く書き方を忘れて検索するのでメモとして残しておきます。

2015/5/3 追記:Material Design の設定方法は、
Xamarin.Android で Material Design を使用する方法 (Android 5.x のみ) - Qiita
Xamarin.Android で Material Design を v7 AppCompat で使用する方法 (Android 2.x/4.x も含む) - Qiita
のエントリーに記載しました。併せてご参照ください。

Theme の種類

Theme.Holo
Theme.Holo.NoActionBar
Theme.Holo.Light.DarkActionBar
Theme.Holo.Light.NoActionBar.FullScreen
Theme.DeviceDefault

あたりを覚えておけば大丈夫そうです。DeviceDefault は API 14 以上みたいです。

ここは通常の Android 開発と同じですので、詳しくは R.style | Android DevelopersStyling the Action Bar | Android Developers を参照してください。

Styles.xml (@style/xxx) で指定する方法

例えば以下のように指定します。

Resources/values/Styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- the theme applied to the application or activity -->
    <style name="MyTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
        <item name="android:windowBackground">@drawable/bg</item>
    </style>

    <!-- ActionBar styles -->
    <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">#4AA3DF</item>
    </style>
</resources>

これで Holo Light を使用してウィンドウの背景を drawable/bg.png に、ActionBar の色を #4AA3DF に設定しています。

Activity に Style を指定する場合

スタイルを Activity.cs に次のように設定します。

Activity.cs
[Activity(Label = "AndroidApp", MainLauncher = true, Theme = "@style/MyTheme")]

全体に指定する場合

AndroidManifest.xml に次のように設定します。

Properties/AndroidManifest.xml
<application android:label="AndroidApp" android:theme="@style/MyTheme">

直接指定する方法

カスタマイズの必要もなく、例えば NoActionBar だけ指定したい場合などは次のように直接指定しても大丈夫なようです。

Activity.cs
[Activity(Label = "AndroidApp", MainLauncher = true, Theme = "@android:style/Theme.Holo.Light.NoActionBar")]
Properties/AndroidManifest.xml
<application android:label="Android" android:theme="@android:style/Theme.Holo.Light.NoActionBar">

Xamarin 気になった方は

是非 ダウンロード(直接) / ダウンロード(弊社経由) して触ってみてください。
学習用リソースJXUG リンクページ に参考資料を纏めてますので併せてどうぞ。

私のはてなブログも購読いただいたりすると嬉しいです。

以上です。

19
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
18