0

正在使用TextInputLayout如下爲什麼不能我使用TextInputLayout(從支持設計庫)全無Theme.Appcompat

<android.support.design.widget.TextInputLayout 
    android:id="@+id/text_input_layout_name" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <EditText 
     android:id="@+id/edit_text_name" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:hint="@string/hint_full_name" 
     android:inputType="text" /> 
</android.support.design.widget.TextInputLayout> 

的代碼工作正常,如果我的應用程序使用Theme.AppCompat

Theme.AppCompat具有強制性對於下面的棒棒糖是有效的,因此我在values \ theme.xml中使用它。

但我的問題是爲什麼我不能使用材料主題的棒棒糖向前,即當我在value-v21 \ theme.xml中使用Theme.Material應用程序崩潰.... 關於這個問題的任何線索?

<style name="MyTheme" parent="@android:style/Theme.Material.Light.DarkActionBar"> 

下面的RuntimeException 應用程序崩潰在充氣我得到他的二進制充氣錯誤XML

Caused by: java.lang.RuntimeException: Failed to resolve attribute at index 18 
     at android.content.res.TypedArray.getColor(TypedArray.java:401) 
     at android.support.design.widget.CollapsingTextHelper.setCollapsedTextAppearance(CollapsingTextHelper.java:166) 
     at android.support.design.widget.TextInputLayout.<init>(TextInputLayout.java:106) 
     at java.lang.reflect.Constructor.newInstance(Native Method) 
     at java.lang.reflect.Constructor.newInstance(Constructor.java:288) 
     at android.view.LayoutInflater.createView(LayoutInflater.java:607) 
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) 
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:381) 
     at android.app.Activity.setContentView(Activity.java:2144) 
     at com.example.trybindinglib.MainActivity.onCreate(MainActivity.java:24) 
     at android.app.Activity.performCreate(Activity.java:5933) 
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2407) 
     at android.app.ActivityThread.access$800(ActivityThread.java:149) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:211) 
     at android.app.ActivityThread.main(ActivityThread.java:5321) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:372) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811) 
+0

由於您已經在您的項目中支付包括AppCompat在內的字節價格,因此在所有API級別使用AppCompat會出現什麼問題?最重要的是,您不必擔心值-V21,因爲您將在任何地方使用相同的代碼。你認爲你會得到什麼? (不要忘了,AppCompat不僅僅是Action Bar或者Material design,還包括自Lollipop以來的很多bug修復和功能,直到現在針對資源。) –

+0

使用Appcompat時沒有問題,juts好奇它爲什麼沒有Material設計支持棒棒糖 – zenith

回答

0

小工具從設計庫依靠功能從Android的最新API級別反向移植。這包括對真實可繪製,顏色和屬性解析以及使用AppCompat版本的平臺屬性(如colorAccent,colorControlNormal,colorError等)的支持。

如果您的應用程序已經在API 21以下的平臺上使用AppCompat,那麼您可以安全地使用上面的AppCompat以及API 21。不僅如此,我鼓勵你。它包含從更新的API級別反向移植的錯誤修正和功能。

除非您確切知道自己在做什麼,否則不要試圖同時使用AppCompat和Material主題

如果您的應用程序使用minSdkVersion 21進行設計,並且您決定不想使用AppCompat,那麼只有一個設計庫的分支只使用框架功能。

https://github.com/commonsguy/cwac-crossport

它依然採用了support-v4庫的部分(這是完全正常):

該項目取決於support-annotations和三塊前support-v4的:support-compatsupport-core-uisupport-core-utils。所有的東西都會通過傳遞依賴關係被引入,並且您可能已經在使用這些依賴關係的一部分或全部了。

+0

這看起來是最接近我的查詢答案。 – zenith

0

使用此樣式TextInputLayout:

<style name="MyTheme" parent="Widget.Design.TextInputLayout"> 
+0

沒有解決我的問題 – zenith

相關問題