Using TextInputLayout layout without changing Application Theme

gladiator

When I am using textInputLayout withOut AppCompat theme in the application, I am not able to inflate the layout and my app is crashing. When I tried setting Appcompat theme for TextInputLayout alone, it worked fine for devices with API's above 21, but it is still crashing for pre lollipop devices. Is there a way to use TextInputLayout on PreLollipop devices without using AppCompat theme for the whole application ?

Eugen Pechanec

TextInputLayout needs a theme derived from a Design theme. First you need to get a context with such theme.

val themedContext = ContextThemeWrapper(context, R.style.Theme_Design_Light)

In here context is an activity. Now you have two options:

1) Inflate the input layout from XML

val inflater = LayoutInflater.from(themedContext)
inflater.inflate(R.layout.my_input_layout, inputParent, true)
// Find the input layout and edit text by ID and work with them.

inputParent is a view group where the input layout will be attached after inflation.

2) Create the input layout in Java

val inputLayout = TextInputLayout(themedContext)
val editText = EditText(inputLayout.context)
inputLayout.addView(editText)
inputParent.addView(inputLayout)

I recommend option 1 because it's what most people are used to when defining view hierarchies. it may help you avoiding unexpected results.

Or just use the AppCompat theme and AppCompatActivity because why the hell not.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Changing checkbox layout without using label

From Dev

Changing layout background depending on theme

From Dev

hiding part of table using javascript without changing the table layout

From Dev

Change layout of elements using CSS without changing HTML

From Dev

WordPress woocommerce plugin changing theme layout

From Dev

WordPress woocommerce plugin changing theme layout

From Dev

Changing theme of whole application in Application class

From Dev

Changing Android styles by using theme

From Dev

Changing theme using web method

From Dev

struts2, How to update Standard two-column table layout for the HTML Struts Tags without changing theme

From Dev

Changing theme of an activity without recreating activity

From Dev

Changing WordPress Theme Bootstrap without editing the php

From Dev

Magento: different home page for each theme, but using same store view, and without changing URL?

From Dev

Changing app theme at runtime using using external theme file

From Dev

How to create Android application without ActionBar using new theme in API9?

From Dev

Awesome WM: Rearrange windows without changing layout

From Dev

Awesome WM: Rearrange windows without changing layout

From Dev

Increase/decrease size of image without changing layout

From Dev

How to define a custom Application theme to specify a default background for a layout in Android?

From Dev

How to change/get the font(-size) in the "Console Application" using Windows API or internal command without changing the registry directly?

From Dev

Changing layout in table row using CSS only

From Dev

Changing log level without restarting application

From Java

Dynamically changing log level without restarting the application

From Dev

Changing Beacons Minor and Major without specific application

From Dev

Using KDE System Theme in Pure Qt Application

From Dev

Using theme for my Qt widget application

From Dev

changing nivoslider numbers into bullets, not working even using theme

From Dev

Italian keyboard: entering tilde (~) and backtick (`) characters without changing keyboard layout

From Dev

Changing layout contolls properties without working in xml and just with java

Related Related

  1. 1

    Changing checkbox layout without using label

  2. 2

    Changing layout background depending on theme

  3. 3

    hiding part of table using javascript without changing the table layout

  4. 4

    Change layout of elements using CSS without changing HTML

  5. 5

    WordPress woocommerce plugin changing theme layout

  6. 6

    WordPress woocommerce plugin changing theme layout

  7. 7

    Changing theme of whole application in Application class

  8. 8

    Changing Android styles by using theme

  9. 9

    Changing theme using web method

  10. 10

    struts2, How to update Standard two-column table layout for the HTML Struts Tags without changing theme

  11. 11

    Changing theme of an activity without recreating activity

  12. 12

    Changing WordPress Theme Bootstrap without editing the php

  13. 13

    Magento: different home page for each theme, but using same store view, and without changing URL?

  14. 14

    Changing app theme at runtime using using external theme file

  15. 15

    How to create Android application without ActionBar using new theme in API9?

  16. 16

    Awesome WM: Rearrange windows without changing layout

  17. 17

    Awesome WM: Rearrange windows without changing layout

  18. 18

    Increase/decrease size of image without changing layout

  19. 19

    How to define a custom Application theme to specify a default background for a layout in Android?

  20. 20

    How to change/get the font(-size) in the "Console Application" using Windows API or internal command without changing the registry directly?

  21. 21

    Changing layout in table row using CSS only

  22. 22

    Changing log level without restarting application

  23. 23

    Dynamically changing log level without restarting the application

  24. 24

    Changing Beacons Minor and Major without specific application

  25. 25

    Using KDE System Theme in Pure Qt Application

  26. 26

    Using theme for my Qt widget application

  27. 27

    changing nivoslider numbers into bullets, not working even using theme

  28. 28

    Italian keyboard: entering tilde (~) and backtick (`) characters without changing keyboard layout

  29. 29

    Changing layout contolls properties without working in xml and just with java

HotTag

Archive