IEには対応していません。Edgeでサイトを開く ≫

ソースコード source code

下記アプリの主要なソースコードを公開しています。アプリ開発の参考になれば幸いです。

画像等が別途必要ですので下記情報のみでアプリが完成するものではありません。 アプリは少しずつ機能拡張していますのでストア公開されているアプリと内容が異なる場合があります。 コードはコピーして自由にお使いいただけます。ただし著作権は放棄しておりませんので全部の再掲載はご遠慮ください。部分的に再掲載したり、改変して再掲載するのは構いません。 自身のアプリ作成の参考として個人使用・商用問わず自由にお使いいただけます。 コード記述のお手本を示すものではありません。ミニアプリですので変数名などさほど気遣いしていない部分も有りますし間違いも有るかと思いますので参考程度にお考え下さい。 他の賢者の皆様が公開されているコードを参考にした箇所も含まれます。Androidアプリ開発の熟練者が書いたコードではありません。 エンジニア向け技術情報共有サービスではありませんので説明は省いています。ご了承ください。 GitHubなどへの公開は予定しておりません。

下記コードの最終ビルド日: 2021-05-08

build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.4.32"
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app/build.gradle

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "jp.aosystem.inunohi"
        minSdkVersion 21
        targetSdkVersion 30
        multiDexEnabled true
        versionCode 3
        versionName "1.2"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true
        }
    }

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        viewBinding true
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'com.google.android.gms:play-services-ads:20.1.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

app/src/main/AndroidManifest.xml

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

    <uses-permission android:name="android.permission.INTERNET" />

    <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.Inunohi">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".SettingActivity" />
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-0000000000000000~0000000000">
        </meta-data>
    </application>

</manifest>

app/src/main/java/jp/aosystem/inunohi/MainActivity.kt

package jp.aosystem.inunohi

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.DisplayMetrics
import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.AdSize
import com.google.android.gms.ads.AdView
import com.google.android.gms.ads.MobileAds
import jp.aosystem.inunohi.databinding.ActivityMainBinding
import java.text.SimpleDateFormat
import java.util.*

class MainActivity : AppCompatActivity() {
    private lateinit var binding: ActivityMainBinding
    private lateinit var viewModel: ConstraintLayout
    private var colorBackSunday: Int = 0
    private var colorBackSaturday: Int = 0
    private var colorBackWeekday: Int = 0
    private var colorBackDogday: Int = 0
    private var colorTextWeekday: Int = 0
    private var colorTextToday: Int = 0
    private val calToday: Calendar = Calendar.getInstance()     //今日
    private val calCurrent: Calendar = Calendar.getInstance()     //指定のYearMonthの1日
    private var todayYear: Int = 0      //今日
    private var todayMonth: Int = 0      //今日
    private var todayDay: Int = 0      //今日
    private var textDays: Array<TextView> = arrayOf()

    //adMob
    private lateinit var adView: AdView     //adMob
    private val adSize: AdSize
        get() {
            val display = windowManager.defaultDisplay
            val outMetrics = DisplayMetrics()
            display.getMetrics(outMetrics)
            val density = outMetrics.density
            var adWidthPixels = this.binding.adContainer.width.toFloat()
            if (adWidthPixels == 0f) {
                adWidthPixels = outMetrics.widthPixels.toFloat()
            }
            val adWidth = (adWidthPixels / density).toInt()
            return AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(this, adWidth)
        }

    companion object {
        //private const val AD_UNIT_ID: String = "ca-app-pub-3940256099942544/6300978111"     //adMob Test
        private const val AD_UNIT_ID: String = "ca-app-pub-0000000000000000/0000000000"     //adMob
        private const val RESULT_SETTING_ACTIVITY: Int = 1
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //setContentView(R.layout.activity_main)
        this.binding = ActivityMainBinding.inflate(layoutInflater)
        this.viewModel = this.binding.root
        setContentView(this.viewModel)
        //タイトルバー非表示
        supportActionBar?.hide()
        //adMob
        MobileAds.initialize(this) {}
        this.adView = AdView(this)
        this.binding.adContainer.addView(this.adView)
        loadBanner()
        //テーマ設定
        this.setTheme()
    }

    override fun onResume() {
        super.onResume()
        this.calToday.time = Date()
        this.todayYear = calToday.get(Calendar.YEAR)
        this.todayMonth = calToday.get(Calendar.MONTH) + 1   //0..11だから+1する
        this.todayDay = calToday.get(Calendar.DAY_OF_MONTH)
        this.calCurrent.set(this.todayYear, this.todayMonth - 1, 1)
        this.textDays = arrayOf(
            this.binding.textDay0,
            this.binding.textDay1,
            this.binding.textDay2,
            this.binding.textDay3,
            this.binding.textDay4,
            this.binding.textDay5,
            this.binding.textDay6,
            this.binding.textDay7,
            this.binding.textDay8,
            this.binding.textDay9,
            this.binding.textDay10,
            this.binding.textDay11,
            this.binding.textDay12,
            this.binding.textDay13,
            this.binding.textDay14,
            this.binding.textDay15,
            this.binding.textDay16,
            this.binding.textDay17,
            this.binding.textDay18,
            this.binding.textDay19,
            this.binding.textDay20,
            this.binding.textDay21,
            this.binding.textDay22,
            this.binding.textDay23,
            this.binding.textDay24,
            this.binding.textDay25,
            this.binding.textDay26,
            this.binding.textDay27,
            this.binding.textDay28,
            this.binding.textDay29,
            this.binding.textDay30,
            this.binding.textDay31,
            this.binding.textDay32,
            this.binding.textDay33,
            this.binding.textDay34,
            this.binding.textDay35,
            this.binding.textDay36,
            this.binding.textDay37,
            this.binding.textDay38,
            this.binding.textDay39,
            this.binding.textDay40,
            this.binding.textDay41,
        )
        this.colorBackSunday = ContextCompat.getColor(this,R.color.backSunday)
        this.colorBackSaturday = ContextCompat.getColor(this,R.color.backSaturday)
        this.colorBackWeekday = ContextCompat.getColor(this,R.color.backWeekday)
        this.colorBackDogday = ContextCompat.getColor(this,R.color.backDogDay)
        this.colorTextWeekday = ContextCompat.getColor(this,R.color.textWeekday)
        this.colorTextToday = ContextCompat.getColor(this,R.color.textToday)
        this.calendarStart()
    }

    //adMob
    private fun loadBanner() {
        this.adView.adUnitId = AD_UNIT_ID
        this.adView.adSize = adSize
        val adRequest = AdRequest
            .Builder()
            //.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .build()
        this.adView.loadAd(adRequest)
    }

    private fun calendarStart() {
        this.clearCalendar()   //カレンダーをクリアする
        //
        val year: Int = this.calCurrent.get(Calendar.YEAR)          //表示する年
        val month: Int = this.calCurrent.get(Calendar.MONTH) + 1    //表示する月
        this.binding.textYearMonth.text = "${year.toString()}年${month.toString()}月"
        val week: Int = this.calCurrent.get(Calendar.DAY_OF_WEEK)
        val lastDay: Int = this.calCurrent.getActualMaximum(Calendar.DATE)
        val unixTimeDate: Date = SimpleDateFormat("yyyy-M-dd").parse("${year.toString()}-${month.toString()}-01")
        val unixTimeDay: Int = unixTimeDate.time.div(86400000).toInt()    //1000 * 3600 * 24
        for (i in 1..lastDay) {
            //日付
            this.textDays[i + week - 2].text = i.toString()
            //当日を着色
            if (year == todayYear && month == todayMonth && i == todayDay) {
                this.textDays[i + week - 2].setTextColor(this.colorTextToday)
            }
             //戌の日を背景着色
            if ((unixTimeDay + i + 7) % 12 == 0) {
                this.textDays[i + week - 2].setBackgroundColor(this.colorBackDogday)
            }
        }
    }

    private fun clearCalendar() {
        for (element in this.textDays) {
            element.text = ""
            element.setTextColor(this.colorTextWeekday)
            element.setBackgroundColor(colorBackWeekday)
        }
        //日曜、土曜を背景着色
        for (i in this.textDays.indices) {
            when (i % 7) {
                0 -> this.textDays[i].setBackgroundColor(this.colorBackSunday)
                6 -> this.textDays[i].setBackgroundColor(this.colorBackSaturday)
            }
        }
    }

    fun onClickPrevYear(v: View) {
        val y: Int = calCurrent.get(Calendar.YEAR) - 1  //prev
        val m: Int = calCurrent.get(Calendar.MONTH) + 1     //0..11だから+1する
        this.calCurrent.set(y, m - 1, 1)
        this.calendarStart()
    }

    fun onClickNextYear(v: View) {
        val y: Int = calCurrent.get(Calendar.YEAR) + 1  //next
        val m: Int = calCurrent.get(Calendar.MONTH) + 1     //0..11だから+1する
        this.calCurrent.set(y, m - 1, 1)
        this.calendarStart()
    }

    fun onClickPrevMonth(v: View) {
        var y: Int = calCurrent.get(Calendar.YEAR)
        var m: Int = calCurrent.get(Calendar.MONTH) + 1     //0..11だから+1する
        m -= 1  //前月
        if (m <= 0) {
            m = 12
            y -= 1
        }
        this.calCurrent.set(y, m - 1, 1)
        this.calendarStart()
    }

    fun onClickNextMonth(v: View) {
        var y: Int = calCurrent.get(Calendar.YEAR)
        var m: Int = calCurrent.get(Calendar.MONTH) + 1     //0..11だから+1する
        m += 1  //次月
        if (m > 12) {
            m = 1
            y += 1
        }
        this.calCurrent.set(y, m - 1, 1)
        this.calendarStart()
    }

    fun onClickToday(v: View) {
        val y: Int = calToday.get(Calendar.YEAR)
        val m: Int = calToday.get(Calendar.MONTH) + 1     //0..11だから+1する
        this.calCurrent.set(y, m - 1, 1)
        this.calendarStart()
    }

    fun onClickSetting(v: View) {
        val intent = Intent(applicationContext, SettingActivity::class.java)
        val themeNumber: Int = this.loadThemeNumber()
        intent.putExtra("themeNumber", themeNumber)
        startActivityForResult(intent, RESULT_SETTING_ACTIVITY)
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
        super.onActivityResult(requestCode, resultCode, intent)
        if (resultCode == Activity.RESULT_OK && requestCode == RESULT_SETTING_ACTIVITY && intent != null) {
            val themeNumber: Int = intent.getIntExtra("themeNumber", 0)
            if (this.loadThemeNumber() != themeNumber) {
                this.saveThemeNumber(themeNumber)
                recreate()
            }
        }
    }

    //テーマを保存
    private fun saveThemeNumber(themeNumber: Int) {
        getSharedPreferences("settings", Context.MODE_PRIVATE).edit().apply {
            putInt("themeNumber", themeNumber)
            apply()
        }
    }

    //テーマを読み出し
    private fun loadThemeNumber(): Int {
        val pref = getSharedPreferences("settings", Context.MODE_PRIVATE)
        return pref.getInt("themeNumber", 0)
    }

    //テーマを設定
    private fun setTheme() {
        when (this.loadThemeNumber()) {
            0 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
            1 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
        }
    }

}

app/src/main/java/jp/aosystem/inunohi/SettingActivity.kt

package jp.aosystem.inunohi

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import jp.aosystem.inunohi.databinding.ActivitySettingBinding

class SettingActivity : AppCompatActivity() {
    private lateinit var binding: ActivitySettingBinding
    private lateinit var viewModel: ConstraintLayout

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //setContentView(R.layout.activity_main)
        this.binding = ActivitySettingBinding.inflate(layoutInflater)
        this.viewModel = this.binding.root
        setContentView(this.viewModel)
        //データ受け取り
        val intent = this.intent
        val themeNumber: Int = intent.getIntExtra("themeNumber",0)
        this.binding.switchTheme.isChecked = themeNumber != 0
        //タイトルバー非表示
        supportActionBar?.hide()
    }

    fun onClickApply(v: View) {
        val themeNumber = if (this.binding.switchTheme.isChecked) 1 else 0
        val intent = Intent()
        intent.putExtra("themeNumber", themeNumber)
        setResult(Activity.RESULT_OK, intent)
        finish()
    }

    fun onClickCancel(v: View) {
        val intent = Intent()
        setResult(Activity.RESULT_CANCELED, intent)
        finish()
    }
}

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

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/backBase"
        android:orientation="vertical">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/backTitle"
                    android:orientation="horizontal">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:orientation="vertical">

                        <TextView
                            android:id="@+id/textDummy"
                            android:layout_width="match_parent"
                            android:layout_height="24dp"
                            android:gravity="center"
                            android:text="@string/setting"
                            android:textColor="@android:color/transparent" />
                    </LinearLayout>

                    <TextView
                        android:id="@+id/textTitle"
                        android:layout_width="wrap_content"
                        android:layout_height="48dp"
                        android:layout_weight="8"
                        android:gravity="center"
                        android:text="@string/title" />

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:orientation="vertical">

                        <TextView
                            android:id="@+id/textSetting"
                            android:layout_width="match_parent"
                            android:layout_height="24dp"
                            android:background="@color/backSetting"
                            android:gravity="center"
                            android:onClick="onClickSetting"
                            android:text="@string/setting" />
                    </LinearLayout>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="horizontal">

                    <TextView
                        android:id="@+id/textPrevYear"
                        android:layout_width="wrap_content"
                        android:layout_height="48dp"
                        android:layout_weight="1"
                        android:background="@color/backPrevYear"
                        android:gravity="center"
                        android:onClick="onClickPrevYear"
                        android:text="@string/prevYear" />

                    <TextView
                        android:id="@+id/textNextYear"
                        android:layout_width="wrap_content"
                        android:layout_height="48dp"
                        android:layout_weight="1"
                        android:background="@color/backNextYear"
                        android:gravity="center"
                        android:onClick="onClickNextYear"
                        android:text="@string/nextYear" />

                    <TextView
                        android:id="@+id/textPrevMonth"
                        android:layout_width="wrap_content"
                        android:layout_height="48dp"
                        android:layout_weight="1"
                        android:background="@color/backPrevMonth"
                        android:gravity="center"
                        android:onClick="onClickPrevMonth"
                        android:text="@string/prevMonth" />

                    <TextView
                        android:id="@+id/textNextMonth"
                        android:layout_width="wrap_content"
                        android:layout_height="48dp"
                        android:layout_weight="1"
                        android:background="@color/backNextMonth"
                        android:gravity="center"
                        android:onClick="onClickNextMonth"
                        android:text="@string/nextMonth" />

                    <TextView
                        android:id="@+id/textToday"
                        android:layout_width="wrap_content"
                        android:layout_height="48dp"
                        android:layout_weight="1"
                        android:background="@color/backToday"
                        android:gravity="center"
                        android:onClick="onClickToday"
                        android:text="@string/today" />
                </LinearLayout>

                <TextView
                    android:id="@+id/textYearMonth"
                    android:layout_width="match_parent"
                    android:layout_height="48dp"
                    android:background="@color/backYearMonth"
                    android:gravity="center" />

                <TableLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <TableRow
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@color/backYearMonth">

                        <TextView
                            android:id="@+id/textWeek0"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="@color/backSunday"
                            android:gravity="center"
                            android:text="@string/week0" />

                        <TextView
                            android:id="@+id/textWeek1"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="@string/week1" />

                        <TextView
                            android:id="@+id/textWeek2"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="@string/week2" />

                        <TextView
                            android:id="@+id/textWeek3"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="@string/week3" />

                        <TextView
                            android:id="@+id/textWeek4"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="@string/week4" />

                        <TextView
                            android:id="@+id/textWeek5"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="@string/week5" />

                        <TextView
                            android:id="@+id/textWeek6"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="1dp"
                            android:layout_weight="1"
                            android:background="@color/backSaturday"
                            android:gravity="center"
                            android:text="@string/week6" />
                    </TableRow>

                    <TableRow
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@color/backYearMonth">

                        <TextView
                            android:id="@+id/textDay0"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backSunday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay1"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay2"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay3"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay4"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay5"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay6"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backSaturday"
                            android:gravity="center"
                            android:text="" />
                    </TableRow>

                    <TableRow
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@color/backYearMonth">

                        <TextView
                            android:id="@+id/textDay7"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backSunday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay8"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay9"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay10"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay11"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay12"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay13"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backSaturday"
                            android:gravity="center"
                            android:text="" />
                    </TableRow>

                    <TableRow
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@color/backYearMonth">

                        <TextView
                            android:id="@+id/textDay14"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backSunday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay15"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay16"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay17"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay18"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay19"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay20"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backSaturday"
                            android:gravity="center"
                            android:text="" />
                    </TableRow>

                    <TableRow
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@color/backYearMonth">

                        <TextView
                            android:id="@+id/textDay21"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backSunday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay22"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay23"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay24"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay25"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay26"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay27"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backSaturday"
                            android:gravity="center"
                            android:text="" />
                    </TableRow>

                    <TableRow
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@color/backYearMonth">

                        <TextView
                            android:id="@+id/textDay28"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backSunday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay29"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay30"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay31"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay32"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay33"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay34"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backSaturday"
                            android:gravity="center"
                            android:text="" />
                    </TableRow>

                    <TableRow
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@color/backYearMonth"
                        android:paddingBottom="1dp">

                        <TextView
                            android:id="@+id/textDay35"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backSunday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay36"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay37"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay38"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay39"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay40"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backWeekday"
                            android:gravity="center"
                            android:text="" />

                        <TextView
                            android:id="@+id/textDay41"
                            android:layout_width="wrap_content"
                            android:layout_height="48dp"
                            android:layout_marginStart="1dp"
                            android:layout_marginTop="1dp"
                            android:layout_weight="1"
                            android:background="@color/backSaturday"
                            android:gravity="center"
                            android:text="" />
                    </TableRow>

                </TableLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="24dp"
                    android:gravity="center"
                    android:orientation="horizontal">

                    <TextView
                        android:id="@+id/textView9"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/usage" />

                    <TextView
                        android:id="@+id/textUsageDogday"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="24dp"
                        android:background="@color/backDogDay"
                        android:text="@string/usageDogday" />

                    <TextView
                        android:id="@+id/textUsageToday"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="24dp"
                        android:text="@string/usageToday"
                        android:textColor="@color/textToday" />

                </LinearLayout>

                <Space
                    android:layout_width="match_parent"
                    android:layout_height="150dp" />
            </LinearLayout>
        </ScrollView>


    </LinearLayout>

    <LinearLayout
        android:id="@+id/ad_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"></LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

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

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".SettingActivity">
    <LinearLayout
        android:id="@+id/layoutButtons"
        android:layout_width="match_parent"
        android:layout_height="48dip"
        android:orientation="horizontal"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <TextView
            android:id="@+id/textCancel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="6"
            android:background="#FFEB3B"
            android:gravity="center"
            android:minHeight="48dip"
            android:onClick="onClickCancel"
            android:text="@string/cancel" />

        <TextView
            android:id="@+id/textVerification"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="6"
            android:background="#CDDC39"
            android:gravity="center"
            android:minHeight="48dip"
            android:onClick="onClickApply"
            android:text="@string/apply" />

    </LinearLayout>
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/layoutButtons">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:orientation="vertical"
            android:paddingLeft="20dp"
            android:paddingTop="20dp"
            android:paddingRight="20dp"
            android:paddingBottom="50dp">

            <androidx.appcompat.widget.SwitchCompat
                android:id="@+id/switchTheme"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="30dp"
                android:text="@string/darkTheme" />

        </LinearLayout>
    </ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>
このページでお気付きの点がございましたら
ご連絡いただけますと幸いです。
Eメール(任意)
送信内容
 

■ 便利ウェブサイト