0

I'm re-writing my app with this layout in Android (using Android Studio 3.6 & Java 8) and noticed that I can't directly set the background color of an EditText or Spinner because the background used contains the e.g. EditText's line (the line the text is written on).

To work around that in my iOS app I simply gave that UI element (with an otherwise transparent background) a View parent that uses the right background color. In Android Studio this works the same way if I use an e.g. LinearLayout as parent but I don't need that layout's full functionality and I'm worried that "abusing" LinearLayouts like this multiple times might affect performance.

There is a View widget in Android Studio but it's not possible to add an EditText or Spinner as its child.

Are there any layouts/views that can be added via Android Studio's UI builder or through xml and that act as the "empty" container I need? What's the best layout to use performance-wise?

Neph
  • 1,823
  • 2
  • 31
  • 69
  • try setting "backgrund" attribute of Edittext with color, i am sure it will work – Khalid Saeed Mar 06 '20 at 15:33
  • @KhalidSaeed That's what I tried first but it doesn't work for the reason I already mentioned in the question: The background of an `EditText` contains the "line" its text is written on. To be exact, it's the `edit_text_material`, which is an Android drawable. If I set a background color instead, the `EditText` turns e.g. red but the line is gone and the element changes height. This ["problem"](https://stackoverflow.com/q/18693639/2016165) also comes up as the very first search result. – Neph Mar 09 '20 at 09:24
  • in that case you can set height and width to match_parent then it will cover the whole box – Khalid Saeed Mar 11 '20 at 18:36
  • @KhalidSaeed I know but as soon as I get rid of the existing background/material, the line at the bottom is gone, which means that there's no indication that it's even an `EditText` that can be clicked into. To change the background color, you either have to create a custom `EditText` (pretty sure there's already code for that) or use the trick I'm currently using and that takes advantage of the UI element's transparency (which doesn't require someone else's code). – Neph Mar 12 '20 at 10:05

0 Answers0