shuhelohelo’s blog

Xamarin.Forms多めです.

Xamarin.FormsのAndroidアプリのアプリ名を変更する

20200714追記

「アプリ名を変更する」と書きましたが,この記事で変更するのはAndroidのホーム画面に表示されるアイコンのラベルでした.

この記事のとおりに作業してもアプリ名は変更されません.

アプリ名の変更は以下の記事を参考にしてください.

shuhelohelo.hatenablog.com

元の記事ここから

前回はXamarin.FormsのAndroidアプリのアイコンを変更しました.

shuhelohelo.hatenablog.com

しかし,アプリ名はプロジェクト名のまま(XFMyDecode2020)でした.

これをプロジェクト名ではなく,任意の名前にしたいと思います.

アプリ名を変更するにはどうしたらよいでしょうか.

ここでCovid19Radarの場合を見てみます.

これはAndroidプロジェクトのMainActivity.csです.

    [Activity(Label = "@string/app_name", Icon = "@mipmap/ic_launcher", Theme = "@style/MainTheme.Splash", MainLauncher = true, LaunchMode = LaunchMode.SingleTop, ScreenOrientation = ScreenOrientation.Portrait, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]

Label = "@string/app_name"と指定しています.

app_nameに割り当てられている文字列がここに入るようです.

ではこのapp_nameはどこで定義されているかというと,AndroidプロジェクトのResources > valuesフォルダ内のStrings.xmlというファイルに記述されています.

f:id:shuhelohelo:20200706163209p:plain

中を見てみると,アプリケーション名が定義されています.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">COVID-19 Contact App</string>
</resources>

同じようにしてみます.valuesフォルダ内にStrings.xmlという名前のファイルを作成します.

アプリ名をMy de:code 2020とします.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">My de:code 2020</string>
</resources>

次にMainActivity.csファイルのActivity属性を同じように以下のように@string/app_nameとしました.

    [Activity(Label = "@string/app_name", Icon = "@mipmap/ic_launcher", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]

これで実行してみます.

f:id:shuhelohelo:20200706164613p:plain

無事,アプリ名も変わりました.