1

I want to remove an editText default transparency which I saw on android 4.
I already tried to solve the problem with alpha=1 on styles in v11 and v14 folders.
But that's not working.

This is my styles.xml :

<resources>

<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
    <!-- API 11 theme customizations can go here. -->
    <item name="android:editTextStyle">@style/MyEditText</item>
</style>

<style name="MyEditText" parent="android:Widget.EditText">
    <item name="android:alpha">1.0</item>
</style>

(style for API 14 is the same)

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Nahid OG
  • 131
  • 4
  • 16

1 Answers1

1

You have to change the background drawable. The reason it is transparent is that the Holo theme's edit text background is based on a 9 patch that has a solid underline, while the rest of the area is transparent.

<style name="MyEditText" parent="android:Widget.EditText">
    <item name="android:background">@drawable/my_edit_text_background</item>
</style>

You will need to define your own background drawable, which should probably be a state list drawable so it will look different depending on whether it is in focus.

Tenfour04
  • 83,111
  • 11
  • 94
  • 154
  • isn't there any better way so i have the same editText style just without transparency? – Nahid OG Feb 06 '14 at 17:44
  • 1
    I'm not sure what you mean by better way. The look of the edit text is hard-coded into Android. There is no hard-coded opaque version, so you have to do your own. This post shows a way to create a drawable in XML that looks like the same style, but you could change the colors around to be whatever opaque color you are wanting: http://stackoverflow.com/a/8212093/506796 – Tenfour04 Feb 06 '14 at 18:25
  • I mean modifying the embedded style to make an opaque version. For example we can adjust our desire text color to all textViews on any Theme, is that impossible to set a particular alpha on Theme's editTexts background? – Nahid OG Feb 06 '14 at 18:38
  • There's no way to do this at run time--you will have to prepare something. The best you could do at run time is to use a ColorMatrixFilter to change the alpha of all the pixels in the drawable to 1, but those pixels will probably appear black, not white. And anyway that would have to be applied manually in code to each EditText in your layout. – Tenfour04 Feb 06 '14 at 22:16
  • Another option would be to use a FrameLayout with an EditText inside it for every instance of your EditText. You could set the FrameLayout's `android:background="#ffffffff"`. – Tenfour04 Feb 06 '14 at 22:17
  • Using android:background="#ffffffff" either in FrameLayout or EditText causes EditText to lose its own style. So i have to create my own background drawable. Thank you for your help – Nahid OG Feb 07 '14 at 07:04