2017-08-17 50 views
0

我在做這樣的事情在佈局文件如何使用應用程序的命名空間的風格

<android.support.design.widget.TextInputLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="5dp" 
      android:layout_marginTop="5dp" 
      android:textColorHint="@color/colorPrimary" 
      app:hintTextAppearance="@color/colorPrimary"> 

但我想用這種風格在多個地方,所以我試圖把它搬進style.xml文件

<style name="FindInstituteInputTextViewStyle" > 
    <item name="android:layout_width">match_parent</item> 
    <item name="android:layout_height">wrap_content</item> 
    <item name="android:layout_marginTop">5dp</item> 
    <item name="android:layout_marginBottom">5dp</item> 
    <item name="android:textColorHint">@color/colorPrimary</item> 
    <item name="app:hintTextAppearence">colorPrimary</item> 
</style> 

但現在這給了我以下例外。

Error:(2376, 21) No resource found that matches the given name: attr 'app:hintTextAppearence'. 

我也試圖把應用程序命名空間ATTR在<資源> 標籤內style.xml

<resources xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
> 

但同樣它沒有爲我工作。請幫助我,對不起,如果我正在做一些愚蠢的錯誤

回答

0

你沒有創建自己的標籤,所以試圖使用這樣會導致錯誤,因爲你看到它。您創建的自己的樣式通過引用現有標籤來使用,不需要名稱空間。即:

<TextView 
    style="@style/FindInstituteInputTextViewStyle"/

見文檔:https://developer.android.com/guide/topics/ui/themes.html

而且這條線:

<item name="app:hintTextAppearence">colorPrimary</item> 

似乎並不指正常的顏色,所以它不應該編譯。