Theme.AppCompat 在 Android Studio 中找不到

huangapple go评论49阅读模式
英文:

Theme.AppCompat is not found in Android Studio

问题

I need to use Theme.AppCompat.Light.NoActionBar, but Theme.AppCompat is not found in Android Studio
how it looks

I added implementation 'com.android.support:appcompat-v7:28.0.0' to gradle, but the problem still the same

dependencies in gradle:

dependencies {

    implementation 'androidx.core:core-ktx:1.10.1'
    //
    implementation 'androidx.room:room-ktx:2.5.1'
    kapt "androidx.room:room-compiler:2.5.1"
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1'
    implementation 'androidx.preference:preference-ktx:1.2.0'
    implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.google.android.material:material:1.9.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.google.android.material:material:1.10.0-alpha03'
    //
    implementation 'com.google.android.material:material:1.9.0'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
    implementation 'androidx.activity:activity-compose:1.7.1'
    implementation platform('androidx.compose:compose-bom:2022.10.00')
    implementation 'androidx.compose.ui:ui'
    implementation 'androidx.compose.ui:ui-graphics'
    implementation 'androidx.compose.ui:ui-tooling-preview'
    implementation 'androidx.compose.material3:material3'
    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'
    androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00')
    androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
    debugImplementation 'androidx.compose.ui:ui-tooling'
    debugImplementation 'androidx.compose.ui:ui-test-manifest'
}
英文:

I need to use Theme.AppCompat.Light.NoActionBar, but Theme.AppCompat is not found in Android Studio
how it looks

I added implementation 'com.android.support:appcompat-v7:28.0.0' to gradle, but the problem still the same

dependencies in gradle:

dependencies {

    implementation 'androidx.core:core-ktx:1.10.1'
    //
    implementation 'androidx.room:room-ktx:2.5.1'
    kapt "androidx.room:room-compiler:2.5.1"
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1'
    implementation 'androidx.preference:preference-ktx:1.2.0'
    implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.google.android.material:material:1.9.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.google.android.material:material:1.10.0-alpha03'
    //
    implementation 'com.google.android.material:material:1.9.0'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
    implementation 'androidx.activity:activity-compose:1.7.1'
    implementation platform('androidx.compose:compose-bom:2022.10.00')
    implementation 'androidx.compose.ui:ui'
    implementation 'androidx.compose.ui:ui-graphics'
    implementation 'androidx.compose.ui:ui-tooling-preview'
    implementation 'androidx.compose.material3:material3'
    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'
    androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00')
    androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
    debugImplementation 'androidx.compose.ui:ui-tooling'
    debugImplementation 'androidx.compose.ui:ui-test-manifest'
}

I added implementation 'com.android.support:appcompat-v7:28.0.0' to gradle, but the problem still the same

答案1

得分: 1

I think you write in your file theme.xml wrong way.

a common error when you are new to Android is to write like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Theme.ShoppingList" parent="theme.AppCompat.Light.NoActionBar" />
</resources>

or like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Theme.ShoppingList" parent="android:Theme.AppCompat.Light.NoActionBar" />
</resources>

The right way to write the parent theme is to make sure you have it like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Theme.ShoppingList" parent="Theme.AppCompat.Light.NoActionBar" />
</resources>

The parent theme starts with a capital letter "Theme".

英文:

the problem i think you write in your file theme.xml wrong way.
in the "parent" of style.

a common error when you new in android it is write like this:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;resources&gt;
    &lt;style name=&quot;Theme.ShoppingList&quot; parent=&quot;theme.AppCompat.Light.NoActionBar&quot; /&gt;
&lt;/resources&gt;

or like this:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;resources&gt;
    &lt;style name=&quot;Theme.ShoppingList&quot; parent=&quot;android:Theme.AppCompat.Light.NoActionBar&quot; /&gt;
&lt;/resources&gt;

The right way to write parent theme make sure you have like this:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;resources&gt;
    &lt;style name=&quot;Theme.ShoppingList&quot; parent=&quot;Theme.AppCompat.Light.NoActionBar&quot; /&gt;
&lt;/resources&gt;

the parent theme starts with a capital letter "Theme"

答案2

得分: 0

添加这个库

implementation 'androidx.appcompat:appcompat:1.6.1'

确保最新版本已经实现,这将解决问题。
同时注释掉旧的库

implementation 'com.android.support:appcompat-v7:28.0.0'
英文:

add this library

implementation 'androidx.appcompat:appcompat:1.6.1'

make sure latest should implement it will solve the problem.
and also comment the old library

implementation 'com.android.support:appcompat-v7:28.0.0'

huangapple
  • 本文由 发表于 2023年5月22日 16:03:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76304129.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定