Ответ 1
Вы добавили библиотеку поддержки дизайна? Добавьте зависимость:
compile 'com.android.support:design:22.2.0'
к вашему build.gradle
У меня очень простой макет, где я использую новый android.support.design.widget.TextInputLayout
вид из Библиотека поддержки дизайна
<android.support.design.widget.TextInputLayout
android:id="@+id/til"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/textDialog"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="First Name"/>
</android.support.design.widget.TextInputLayout>
При раздувании я получаю исключение:
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)
Вы добавили библиотеку поддержки дизайна? Добавьте зависимость:
compile 'com.android.support:design:22.2.0'
к вашему build.gradle
Если вы используете Theme.AppCompat
в качестве темы вашего базового приложения, укажите textColorError
в нем.
TextInputLayout нуждается в том, чтобы использовать в нем ошибки. Else покажет журнал аварий, как указано выше.
Пример:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="textColorError"> @color/design_textinput_error_color_light </item>
</style>
Это значение @color/design_textinput_error_color_light
для AppCompat.Light
и @color/design_textinput_error_color_dark
для AppCompat.Dark
.
Убедитесь, что тема приложения расширяет тему AppCompat.
<!-- Base application theme. -->
<style name="AppTheme" parent="@style/Theme.AppCompat">
<!-- Customize your theme here. -->
</style>
У меня была такая же проблема с необработанным приложением, созданным с помощью Android Studio.
Я решил это, сначала добавив следующую зависимость к моему build.gradle compile 'com.android.support:appcompat-v7:22.2.0'
Затем мне пришлось изменить базу тем в @style/Theme.AppCompat, как предложил Алексей. Обратите внимание, что вам, вероятно, придется переименовать базовую тему, поскольку в библиотеке appcompat есть один с тем же именем (AppTheme), и AS, похоже, запутался между двумя...
Надеюсь, это поможет!
getColor падает, вы можете попробовать две вещи:
1. Вместо использования EditText используйте android.support.v7.widget.AppCompatEditText. Например:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorEnabled="true">
<android.support.v7.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="First Name"
android:inputType="textPersonName"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
2.Если это не помогает, возможно, но это приведет к удалению цвета вашего подсказки при выборе поля ввода. Добавить:
app:hintTextAppearance="@android:style/TextAppearance.Small"
в TextInputLayout.
Убедитесь, что ваш XML выглядит следующим образом:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="search" />
</android.support.design.widget.TextInputLayout>
полный пример:
http://hmkcode.com/android-textinputlayout/
Нет необходимости изменения темыStyle