0
0

More than 1 year has passed since last update.

【android】各パッケージについて

Posted at

パッケージについて

androidstudioをインストールして、プロジェクトを作成してみました。
メモ程度に何のファイルがあるのか書いてみました。

image.png

java

MainActivity.java
package com.example.helloworld;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    public void exitButton(View view){
        super.finish();
    }
}

mainクラスのようなものですかね、、
setContentView(R.layout.activity_main);でメイン画面の描画をしています。
exitButtonはボタンが押されたときに呼ばれるメソッドです。

manifests

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.helloworld">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.HelloWorld">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

ヘッダーのタイトル部分を定義しているようです。
android:label="@string/app_name"で参照元を指定しています。(参照元にはxmlがあります。)

res

strings.xml
<resources>
    <string name="app_name">テストアプリ</string>
    <string name="hello">こんにちは</string>
</resources>

ここではjavaのファイルや、manifestsからの参照元(xmlの定義)があります。
上記はAndroidManifest.xmlのandroid:label="@string/app_name"と紐づいているxmlファイルです。
name="app_name"と記載があるので、manifestsの"@string/app_name"と紐づいていることがなんとなくわかりますね。

0
0
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
0
0