Bug 31601 - [Android Design Library] Using the TextInputLayout causes exception if activities theme is not set to Theme.AppCompat
Summary: [Android Design Library] Using the TextInputLayout causes exception if activi...
Status: RESOLVED FIXED
Alias: None
Product: Components
Classification: Xamarin
Component: Xamarin Components ()
Version: N/A
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Jon Dick
URL:
Depends on:
Blocks:
 
Reported: 2015-07-02 18:48 UTC by Jon Goldberger [MSFT]
Modified: 2015-07-31 10:37 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Test Project (1.66 MB, application/zip)
2015-07-02 18:48 UTC, Jon Goldberger [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Jon Goldberger [MSFT] 2015-07-02 18:48:00 UTC
Created attachment 11834 [details]
Test Project

## Description

When testing the TextInputLayout added to a XAML file or instantiated in code, an exception was thrown causing the app to crash. 

> java.lang.RuntimeException: Failed to resolve attribute at index 18

The full stack trace looks different of course depending on whether the Widget was added in code or in XAML. But the above error led me to this post:
http://www.metaandroid.com/question/runtimeexception-while-using-new-textinputlayout-from-support-design-library/

which suggested to inherit from the Theme.AppCompat, and after doing so with:
[Activity(Label = "TestTextInputLayout", MainLauncher = true, Icon = "@drawable/icon", Theme = "@style/Theme.AppCompat")]

then the exception is avoided and the UI loads correctly. 

## Steps to reproduce

1. Open the attached test project and deploy to an API 22 Lollipop device or simulator

Expected result: Will see UI with a button and a TextInputLayout

Actual Result: App crashes with above exception (Stacktrace pasted below).


## Notes

As noted in the description, uncomment the
>Theme = "@style/Theme.AppCompat"
from the MainActivity's Activity attribute to use this theme and the app will launch fine and display the UI with the TextInputLayout. 


## Stacktrace:

>Java.Lang.RuntimeException: Unable to start activity ComponentInfo{com.onobytes.testtextinputlayout/md579d945e52c1f147f9e8fb30b4298cf3e.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class android.support.design.widget.TextInputLayout
>  at --- End of managed exception stack trace ---
>  at java.lang.RuntimeException: Unable to start activity ComponentInfo{com.onobytes.testtextinputlayout/md579d945e52c1f147f9e8fb30b4298cf3e.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class android.support.design.widget.TextInputLayout
>  at at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
>  at at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
>  at at android.app.ActivityThread.access$800(ActivityThread.java:151)
>  at at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
>  at at android.os.Handler.dispatchMessage(Handler.java:102)
>  at at android.os.Looper.loop(Looper.java:135)
>  at at android.app.ActivityThread.main(ActivityThread.java:5254)
>  at at java.lang.reflect.Method.invoke(Native Method)
>  at at java.lang.reflect.Method.invoke(Method.java:372)
>  at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
>  at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
>  at Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class android.support.design.widget.TextInputLayout
>  at at android.view.LayoutInflater.createView(LayoutInflater.java:633)
>  at at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
>  at at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
>  at at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
>  at at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
>  at at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
>  at at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
>  at at android.app.Activity.setContentView(Activity.java:2145)
>  at at md579d945e52c1f147f9e8fb30b4298cf3e.MainActivity.n_onCreate(Native Method)
>  at at md579d945e52c1f147f9e8fb30b4298cf3e.MainActivity.onCreate(MainActivity.java:28)
>  at at android.app.Activity.performCreate(Activity.java:5990)
>  at at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
>  at at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
>  at ... 10 more
>  at Caused by: java.lang.reflect.InvocationTargetException
>  at at java.lang.reflect.Constructor.newInstance(Native Method)
>  at at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
>  at at android.view.LayoutInflater.createView(LayoutInflater.java:607)
>  at ... 22 more
>  at Caused by: java.lang.RuntimeException: Failed to resolve attribute at index 18
>  at at android.content.res.TypedArray.getColor(TypedArray.java:401)
>  at at android.support.design.widget.CollapsingTextHelper.setCollapsedTextAppearance(CollapsingTextHelper.java:166)
>  at at android.support.design.widget.TextInputLayout.<init>(TextInputLayout.java:106)
>  at ... 25 more


## Environment

=== Xamarin Studio ===

Version 5.9.4 (build 5)
Installation UUID: 2dc9022f-f9a8-424f-8284-bf224cbbfde0
Runtime:
	Mono 4.0.2 ((detached/c99aa0c)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400020005

=== Xamarin.Android ===

Version: 5.1.4.16 (Business Edition)
Android SDK: /Users/apple/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Apple Developer Tools ===

Xcode 6.4 (7720)
Build 6E35b

=== Xamarin.iOS ===

Version: 8.10.3.2 (Business Edition)
Hash: 8b265d6
Branch: master
Build date: 2015-06-30 15:19:13-0400

=== Xamarin.Mac ===

Version: 2.0.2.35 (Business Edition)

=== Build Information ===

Release ID: 509040005
Git revision: 8010a90f6e246b32364e3fb46ef2c9d1be9c9a2b
Build date: 2015-06-08 16:52:06-04
Xamarin addins: 7e93e9c3503f28770f23ce1b7eafd829919f18e8

=== Operating System ===

Mac OS X 10.10.4
Darwin Jons-iMac.local 14.4.0 Darwin Kernel Version 14.4.0
    Thu May 28 11:35:04 PDT 2015
    root:xnu-2782.30.5~1/RELEASE_X86_64 x86_64
Comment 1 Jon Dick 2015-07-08 09:19:45 UTC
This is normal and expected behaviour.  Anything you use from the new Design support library will need to be in an activity that has a theme based on Theme.AppCompat.

This is google's doing, not anything we can change the behaviour of in Xamarin.  Unfortunately the error isn't always clear (ran into something similar with the FAB).
Comment 2 Jon Goldberger [MSFT] 2015-07-23 22:12:20 UTC
@Jon Dick,

Thanks for the answer. Perhaps this should be reflected in the getting started guide for the component?
Comment 3 Jon Dick 2015-07-31 10:37:51 UTC
I've updated the documentation in master and it will get pushed out with the next update, thanks :)