-3

我想學習android材質設計。使用工具欄我想更改彈出菜單以及文本顏色。所以,我發現它可以通過添加以下代碼爲什麼應用程序:主題不適用於xml文件?

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#CCC" 
    app:theme="@style/ThemeOverlay.AppCompat.Light" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" 
    android:elevation="4dp" 

    > 
</android.support.v7.widget.Toolbar> 

完成但問題是應用:主題應用:popupTheme不能正常工作,並顯示在Android Studio中的XML文件錯誤。

enter image description here

我能知道?

我使用com.android.support:appcompat-v7:23.0.0

+5

加上'的xmlns:程序=「http://schemas.android.com/ apk/res-auto「'到工具欄,在xml中 – Blackbelt

+0

將光標放在該行上太難了嗎? IDE是強大的工具,它提供了一個小技巧,你需要的只是按Alt + Enter,而不是這個,你在這裏發佈一個問題... downvote –

+0

@ViktorYakunin我在Visual Studio中,沒有提示彈出所以這個問題對我很有幫助。但是,多虧了你,我現在知道如果任何命名空間在xml安卓文件中混亂,我可能會將它們放在Android Studio上以獲取提示! – Elisa

回答

3

你要添加的命名空間在XML文件中。

xmlns:app="http://schemas.android.com/apk/res-auto" 

Somenthing像:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#CCC" 
    app:theme="@style/ThemeOverlay.AppCompat.Light" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" 
    android:elevation="4dp" 
    /> 

此外,由於appcompat v22.1可以在Toolbar使用:

android:theme="@style/ThemeOverlay.AppCompat.Light" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" 
相關問題