0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

名前しか知らないActivityのテーマを調べる方法

Last updated at Posted at 2025-10-16

備忘のためメモ
外部ライブラリのActivityにManifestからstyleにテーマ属性を指定したい && parentにthemeを指定したいときにライブラリの中身を読まずにthemeを調べる方法。
↓を適当な箇所に挿入してアプリをビルド && 実行(書き捨てのコードなので処理は適当)

fun logActivityTheme() {
    try {
        val activityName = "{{ 調べたいActivityのパス }}"
        val packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES)
        for (activityInfo in packageInfo.activities!!) {
            if (activityInfo.name == activityName) {
                val themeName = applicationContext.resources.getResourceName(activityInfo.theme)
                Log.d("DEBUG_LOG", "themeName: $themeName")
            }
        }
    } catch (e: Exception) {
        Log.d("DEBUG_LOG", "Exception: $e")
    }
}

条件をactivityInfo.name.contains(activityName)とかにすればクラス名だけでも調べられるはず。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?