Android: EditText displayed with black background - android

I have a row with two EditTexts and two ImageButtons. In the preview of android studio everything looks fine and the EditTexts have the default style. But if I display it on my tablet the background is black.
How it should look like:
How it looks like on the tablet:
Other EditText-Boxes are displayed correctly.
Does anyone know why the these look different and how I can fix it?
Here the XML-Layout of this line:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_centerHorizontal="true"
>
<EditText
android:id="#+id/first_input"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
/>
<EditText
android:id="#+id/second_input"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2.4"
/>
<ImageButton
android:id="#+id/first_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:src="#drawable/move"
android:background="#drawable/first_button_background"
android:onClick="onFirstButtonClicked"
/>
<ImageButton
android:id="#+id/second_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:src="#drawable/trash"
android:background="#drawable/second_button_background"
android:onClick="onSecondButtonClicked"
/>
</LinearLayout>
EDIT:
I tried changing the background color to white but then the EditTexts lose their whole style so also the underlining will not be displayed anymore.

this's because the editext default background change based on device theme go for an edittext with custom background and in a simple way include android:background="#ffffff" for your editexts

The problem might be occurring due to the imageButtons but You can change the background color of the edittext like this:
android:background="#FFFFFF"

May be your tab does not support the selected theme, try to change background color of your edittext using:
android:background="#FFFFFF"
if problem does not solve, then you can change background of edittext programmatically like this:
youeEditText.setBackgroundColor(Color.parseColor("#ffffff"));

Related

Problems with setEnabled in imagebutton

I have ImageButton, putting setEnabled(false) that is so, but only in the emulator / tablet
But the button does not change anything when I put setEnabled(false) on some devices
Which can be? I would have all the appliances are as in the first image (I've tried using the android: clickable, but without success)
this is my xml:
<LinearLayout
android:id="#+id/MenuBotoes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#fc6719">
<ImageButton
android:id="#+id/btnMarcacao"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/draw"/>
<ImageButton
android:id="#+id/btnZoom"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/zoom"/>
<ImageButton
android:id="#+id/btnBorracha"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/eraser"/>
</LinearLayout>
Setting the button as enabled or disabled will not necessarily change what it looks like, especially in the case of an imagebutton. You may need to make custom selectors/drawables/backgrounds for your images if you want to have different appearances based on state. You can do this by either changing the src or the background of your button to a selector drawable.
See selectors here: https://developer.android.com/guide/topics/resources/drawable-resource.html
And then see here: https://developer.android.com/reference/android/graphics/drawable/StateListDrawable.html

TextInputLayout in listview

When I use Material Design Support TextInputLayout in a Classic Layout, I have no problem, I get the hint animation.
But when I use it inside a listview, I lose this, and it behaves like a classical Edittext.
Why???
Here is my code ( one cell xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/ll_row"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
<android.support.design.widget.TextInputLayout
android:id="#+id/til_valor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="test2"
android:imeOptions="actionNext">
<EditText
android:id="#+id/valor"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="test"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
<ImageButton
android:id="#+id/cambutton"
android:layout_width="50dp"
android:layout_height="match_parent"
android:background="#drawable/button_azul_states"
android:contentDescription="Tomar foto"
android:gravity="center"
android:src="#drawable/ic_action_device_access_camera" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Initially, I had it with LinearLayout, I tried to use NestedScrollView, without success...
Try removing both hint in layout and call setHint only on TextInputLayout instance from code
EDIT:
I realized that my answer is wrong. My case is different because I use a RecyclerView, I've tried with the ListView and the animated hint just won't work...
I suggest you to convert to RecyclerView, it's easy and solves the issue

Android ImageButton with gradient AND transparent image background[Image included]

Id like to achieve the effect seen in the image ive provided below.....possible?
I know how to do a gradient and I know how to set a imagebuttons src/bg to a drawable but i have nooooooo idea where to even start with pulling off both at the same time.
It's actually incredibly simple. To avoid overdraw by layering a bunch of views, just add a ColorFilter to your ImageView:
imageView.setColorFilter(Color.parseColor("#994dace3"), PorterDuff.Mode.SRC_OVER);
No added overdraw, and you can set whatever color you want, and experiment with different PorterDuff blending modes.
Example:
I know how to do a gradient and I know how to set a imagebuttons
src/bg to a drawable but i have nooooooo idea where to even start with
pulling off both at the same time
I think what you are referring to as being a gradient is actually a color with transparency value set. From what I can tell, you are looking for something like this:
You can achieve this using the following layout:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/the_picture"
android:src="#color/transparent_color" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="Message!" />
</RelativeLayout>
The RelativeLayout is used to position the TextView over the ImageButton. The Picture is set as the background. The src is set to a color(any color) with a transparency value between 00(completely transparent) and ff (completely opaque). In the image above, I have used a transparency of 70. So, say you pick Green(#00ff00), add transparent value to it: #7000ff00 and add it to res/values/colors.xml. You can also use it directly as I have done below.
Here's the complete xml code for the activity in the pic above:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/original" />
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/original"
android:src="#7000ff00" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="Optional Message!"
android:gravity="center"
android:textColor="#android:color/white"
android:textSize="25sp" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
You can set a custom font to the TextView(as in the picture you've provided) in code.

Android: Custom AlertDialog has different text color

I created a custom layout for an AlertDialog, and it works fine,
But i have a problem with the text style of my layout.
This is the layout for my alertDialog:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/namedialoglable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/profilename" />
<EditText
android:id="#+id/namedialoginput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/namedialoglable"
android:layout_marginTop="24dp"
android:ems="10"
android:selectAllOnFocus="true"
android:text="#string/defaultname" >
<requestFocus />
</EditText>
</RelativeLayout>
The problem is that the text into the default AlertDialog is white, and in my custom dialog is black. I just want to use the same color used into other AlertDialog.
How to do that?
EDIT
To be more clear:
I want to keep the father text color, not force my custom dialog color to be white. I think that AlertDialog use system color, so my alert need to keep the same color
Why wont you just apply:
android:textColor="#android:color/white"
to the Views you want with while text color.
Also look into styles and themes to achieve what you wnat:
http://developer.android.com/guide/topics/ui/themes.html#PlatformStyles
Ok in my case, i found another solution.
Since my need is to have only a message and an input text into the dialog box, the best solution is to create a layout with only an EditText, like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/namedialoginput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="24dp"
android:ems="10"
android:selectAllOnFocus="true"
android:text="#string/defaultname" >
<requestFocus />
</EditText>
</RelativeLayout>
And for the message text, using the builder method: setMessage:
builder.setView(content)
.setTitle("Profile Name")
.setMessage(R.string.profilename);
In that way, i am sure that i keep the other dialog boxes format.

Android: Dialog background on emulator and my phone are different color

This is the dialog on the emulator:
And this is on my phone:
I tried setting background to my layout but then the title space and bottom space would still be this white color. How do I "repair" it?
If it matters, the second picture is from MIUI ROM.
//EDIT:
Here is my layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<Spinner
android:id="#+id/spinner_minutes"
android:layout_width="170dip"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:entries="#array/timer_values"/>
<TextView
android:id="#+id/text_timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:visibility="gone"/>
<LinearLayout
android:id="#+id/button_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/spinner_minutes"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dip">
<Button
android:id="#+id/button_set"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:text="Set"
android:layout_marginLeft="10dip"
android:layout_marginBottom="5dip" />
<Button
android:id="#+id/button_cancel"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_marginRight="10dip"
android:layout_marginBottom="5dip" />
</LinearLayout>
<LinearLayout
android:id="#+id/button_holder2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/text_timer"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dip"
android:visibility="gone">
<Button
android:id="#+id/button_close"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:text="Close"/>
<Button
android:id="#+id/button_cancel2"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:text="Cancel"/>
</LinearLayout>
</RelativeLayout>
I am creating the dialog this way:
about_dlg=new Dialog(SoundRelaxerActivity.this);
about_dlg.requestWindowFeature(Window.FEATURE_NO_TITLE);
about_dlg.setContentView(R.layout.about_dialog);
about_dlg.show();
This call:
about_dlg=new Dialog(SoundRelaxerActivity.this);
will use the system default theme. Every hardware manufacture develops their own custom system default themes. For example, the default Button might look different on Motorola Blur than it does on HTC Sense. If you want to build a dialog, with a custom theme, use this call instead:
about_dlg = new Dialog(context, android.R.style.Theme);
BUT android.R.style.Theme might not be what you want. Look at http://developer.android.com/reference/android/R.style.html
and check out any of the values defined as Theme_
AND A HEADS UP:
This might not work out of the box. You are going to have to modify your layout xml file to have the appropriate styles relevant to the theme you choose. For example, Android.R.style.Theme defaults to a solid black background.
And lastly,
this might not be worth the effort. While Android Fragmentation is a pain in the butt, sometimes we have to embrace it. The user is used to the default settings of the device-- for example if every dialogue on their phone is white but yours is black, they might be jarred by this. That is a weak example, but hopefully you get the point.
Make sure you are setting the background of the top overall layout (in this case the relative layout)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="#c0c0c0">
The emulator is just using a different default color than your phone. Change #c0c0c0 to whatever color you want
I know on Android 4 you can ask for the default Holo theme for your application which eliminates this possibility as Holo HAS to be present on an Android 4 system. Prior to that, all you've got is the default theme which could be anything at all.
The question is, why is your text white on white on MIUI? Are you setting that explicitly? If you aren't, then I would consider that you're seeing a bug in the theme rather than your app because if the theme author has made these dialogs white then the default text colour should surely be dark or else every app would suffer the same problem.

Categories

Resources