Код: Выделить всё
Android resource linking failed
com.example.m3viewattributetest.app-mergeDebugResources-29:/values/values.xml:2469: error: style attribute 'attr/dynamicColorAllowed (aka com.example.m3viewattributetest:attr/dynamicColorAllowed)' not found.
com.example.m3viewattributetest.app-mergeDebugResources-29:/values-night-v8/values-night-v8.xml:4: error: style attribute 'attr/dynamicColorAllowed (aka com.example.m3viewattributetest:attr/dynamicColorAllowed)' not found.
error: failed linking references.
Код: Выделить всё
package com.example.m3viewattributetest
import android.os.Bundle
import android.util.Log
import android.util.TypedValue
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
companion object {
private const val TAG = "M3ViewTest" // Logcat Tag
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val textViewResult = findViewById(R.id.textViewResult)
var resultText = "M3 Attribute Test Results:\n"
Log.d(TAG, "MainActivity onCreate: Attempting to resolve M3 attributes.")
// Resolve dynamicColorAllowed
val typedValueDynamic = TypedValue()
val resolvedDynamic = theme.resolveAttribute(R.attr.dynamicColorAllowed, typedValueDynamic, true)
val dynamicResult = "dynamicColorAllowed resolved: $resolvedDynamic"
Log.d(TAG, dynamicResult)
resultText += "$dynamicResult\n"
if (resolvedDynamic) {
val dynamicLog = " -> type: ${typedValueDynamic.type}, data: ${typedValueDynamic.data}, string: ${typedValueDynamic.string}"
Log.d(TAG, dynamicLog)
resultText += "$dynamicLog\n"
} else {
Log.e(TAG, "R.attr.dynamicColorAllowed FAILED TO RESOLVE.")
}
// Resolve colorScrim
val typedValueScrim = TypedValue()
val resolvedScrim = theme.resolveAttribute(R.attr.colorScrim, typedValueScrim, true)
val scrimResult = "colorScrim resolved: $resolvedScrim"
Log.d(TAG, scrimResult)
resultText += "\n$scrimResult\n"
if (resolvedScrim) {
val scrimLog = " -> type: ${typedValueScrim.type}, data (color int): #${Integer.toHexString(typedValueScrim.data)}, string: ${typedValueScrim.string}"
Log.d(TAG, scrimLog)
resultText += "$scrimLog\n"
} else {
Log.e(TAG, "R.attr.colorScrim FAILED TO RESOLVE.")
}
// Resolve colorPrimary
val typedValuePrimary = TypedValue()
val resolvedPrimary = theme.resolveAttribute(R.attr.colorPrimary, typedValuePrimary, true)
val primaryResult = "colorPrimary resolved: $resolvedPrimary"
Log.d(TAG, primaryResult)
resultText += "\n$primaryResult\n"
if (resolvedPrimary) {
val primaryLog = " -> type: ${typedValuePrimary.type}, data (color int): #${Integer.toHexString(typedValuePrimary.data)}, string: ${typedValuePrimary.string}"
Log.d(TAG, primaryLog)
resultText += "$primaryLog\n"
} else {
Log.e(TAG, "R.attr.colorPrimary FAILED TO RESOLVE.")
}
textViewResult.text = resultText
}
}
Код: Выделить всё
Код: Выделить всё
dependencies {
implementation("androidx.core:core-ktx:1.12.0") // Or latest stable
implementation("androidx.appcompat:appcompat:1.6.1") // Or latest stable
implementation("com.google.android.material:material:1.11.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
}
Код: Выделить всё
true
Подробнее здесь: https://stackoverflow.com/questions/796 ... attributes
Мобильная версия