When the user is click on the line in EditText in Huawei device he get another smell line (under the long line) - see image.
I try to do a lot of thing to fix it and I don't find what should I do.enter image description here
The is my code:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/static_relative_layout"
android:background="#color/app_default_background"
android:fitsSystemWindows="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="15dp"
android:layout_marginRight="50dp"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="#+id/email_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorTextAppearance="#style/TextInputLayoutHintAppearanceError"
app:hintTextAppearance="#style/TextInputLayoutHintAppearanceValid">
<EditText
android:id="#+id/email_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_email"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:maxLines="1"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:singleLine="true"
android:theme="#style/EditTextStyleRedLine"
android:textColor="#color/new_dark_grey"/>
</android.support.design.widget.TextInputLayout>
The style "EditTextStyleRedLine" is as follows:
<style name="EditTextStyleRedLine" parent="#style/Widget.AppCompat.EditText">
<item name="colorControlNormal">#color/grey</item>
<item name="colorControlActivated">#color/red</item>
</style>
Add a background to your edittext, this will solve your issue.
android: background="#null"
You can personalize the background by creating a new drawable resource file, res > right click drawable > new > drawable resource file. Add the following code:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<!-- Inner Shape -->
<solid
android:color="#color/colorWhite"/>
<!-- OUTLINE -->
<stroke android:width="0dp"
android:color="#FFFFFF"/>
<!-- CORNERS -->
<corners
android:radius="5dp"/>
</shape>
</item>
</selector>
Then you can set
android:background="#drawable/YOUR_DRAWABLE"
Related
I have this main layout. It should display 3 buttons, but I am showing you only 1 button definition in order not to put mostly code in the question.The other buttons have the same definition.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical"
android:paddingTop="70dp"
android:paddingBottom="70dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="center"
android:orientation="horizontal"
android:padding="50dp">
<Button
android:id="#+id/btnRfid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/main_button_background"
android:padding="20dp"
android:text="#string/button_rfid"
android:textSize="36sp"
android:drawableLeft="#drawable/button_rfid"/>
</LinearLayout>
</LinearLayout>
This is the main_button_background.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#FFFFFF"
android:endColor="#949597"
android:angle="270" />
<corners android:radius="20dp" />
<stroke android:width="5px" android:color="#000000" />
</shape>
This is how I see it in design editor of Android Studio:
However, this is how it is viewed in the emulator:
Why are text rendered that way? Is something missing?
By reading tutorials, I don't see anything special in the button definition.
Regards
Jaime
1) Migrate your project to androidx.
2) Include dependency in your build.gradle:
implementation 'com.google.android.material:material:1.0.0'
3) Use in your layout:
<com.google.android.material.button.MaterialButton
android:id="#+id/material_icon_button"
style="#style/Widget.MaterialComponents.Button.Icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/icon_button_label_enabled"
app:icon="#drawable/icon_24px"/>
4) Don't forget to change your applevel theme to Material Component theme.
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
I have a dialog layout in that i have 3 edit texts, for the 1st edit text it shows the underline color as green(primary color), and other two edit text shows the color pink(color accent).
Why so? It should be same as other two edit texts.
Tried to change this with :
name.getBackground().mutate().setColorFilter(getResources().getColor(R.color.colorAccent), PorterDuff.Mode.SRC_ATOP);
name.getBackground().setColorFilter(getResources().getColor(R.color.colorAccent), PorterDuff.Mode.SRC_ATOP);
also by the SO solutions. But nothing helped.
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
....
<item name="android:editTextStyle">#style/EditTextStyle</item>
</style>
<style name="EditTextStyle" parent="Widget.AppCompat.EditText">
<item name="colorControlNormal">#color/border_gray</item>
<item name="colorControlActivated">#color/border_gray</item>
<item name="colorControlHighlight">#color/border_gray</item>
</style>
layout :
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<LinearLayout android:layout_height="50dp"
android:layout_width="match_parent"
android:background="#color/colorPrimary">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Schedule"
android:textColor="#android:color/white"
android:textAppearance="#android:style/TextAppearance.Medium"
android:layout_gravity="center"
android:layout_marginLeft="20dp" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="20dp">
<EditText
android:id="#+id/edt_name"
android:layout_width="match_parent"
android:layout_height="45dp"
android:textColor="#000000"
android:textSize="14sp"
android:inputType="textCapSentences"
android:hint="Name"
android:cursorVisible="false"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp" />
<EditText
android:id="#+id/edt_dateTime"
android:layout_width="match_parent"
android:layout_height="45dp"
android:textColor="#000000"
android:textSize="14sp"
android:cursorVisible="false"
android:inputType="textCapSentences"
android:hint="Date and Time"
android:layout_centerVertical="true"
android:layout_alignLeft="#+id/edt_name"
android:layout_alignStart="#+id/edt_name"
android:layout_below="#+id/edt_name"
android:layout_alignRight="#+id/edt_name"
android:layout_alignEnd="#+id/edt_name"
android:layout_marginTop="05dp" />
<EditText
android:id="#+id/edt_budget"
android:layout_width="match_parent"
android:layout_height="45dp"
android:textColor="#000000"
android:textSize="14sp"
android:cursorVisible="false"
android:hint="Budget"
android:layout_below="#+id/edt_dateTime"
android:layout_alignLeft="#+id/edt_dateTime"
android:layout_alignStart="#+id/edt_dateTime"
android:layout_alignRight="#+id/edt_dateTime"
android:layout_alignEnd="#+id/edt_dateTime"
android:layout_marginTop="05dp"
android:inputType="number" />
</RelativeLayout>
</LinearLayout>
This is what i got after implementing drawable.
Thank you..
It simply consists of overriding the value for colorControlActivated, colorControlHighlight and colorControlNormal in your app theme definition
<style name="Theme.App.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorControlNormal">#c5c5c5</item>
<item name="colorControlActivated">#color/accent</item>
<item name="colorControlHighlight">#color/accent</item>
</style>
or by java
editText.getBackground().mutate().setColorFilter(getResources().getColor(R.color.your_color), PorterDuff.Mode.SRC_ATOP);
by changing your "colorAccent" color you will change color or edittext bottom line and text input layout as well.
Create textfield_bg_drawable.xml in drawable folder. and set it as background resource in EditText.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="2dp"
android:left="-2dp"
android:right="-2dp"
android:top="-2dp">
<selector>
<item
android:state_enabled="true"
android:state_focused="true">
<shape android:shape="rectangle">
<stroke
android:width="2dp"
android:color="#color/focused_line_color" />
</shape>
</item>
<item android:state_enabled="true">
<shape android:shape="rectangle">
<stroke
android:width="1dp"
android:color="#color/normal_line_color" />
</shape>
</item>
</selector>
</item>
</layer-list>
Try with this following code properly working on my side
Drawable drawable = editText.getBackground(); // get current EditText drawable
drawable.setColorFilter(Color.GREEN, PorterDuff.Mode.SRC_ATOP); // change the drawable color
if (Build.VERSION.SDK_INT > 16) {
editText.setBackground(drawable); // set the new drawable to EditText
} else {
editText.setBackgroundDrawable(drawable); // use setBackgroundDrawable because setBackground required API 16
}
Where editText is the id of your EditText
I think it is because Your 1st editText focusing, when your alert layout appear.
add this line in your editText
android:focusable="true"
You need to disable focus from your first edittext when the activity is opened, so set
android:requestFocus= "false"
in your xml file. Or try the following
edittext.clearFocus();
in your java file.
It will not pick your primary color then.
Hope it works!
these are how my spinner and edit text looks like :
these are spinner and edit text that I saw somewhere else and I liked them :
How can I change my edittext and spinners to looks the second image ?
I'm using app compact anyway
thanks
Set Background for Spinner and EditText will help you to figure it out.
<Spinner android:id="#+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/spinner_bg"/>
<EditText android:id="#+id/edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/edittext_bg"/>
</LinearLayout>
By now I can guide you for EditText section ..
Define your style drawable like this ..
res/drawable/edit_text_style.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape >
<solid android:color="#color/wine_red" />
</shape>
</item>
<!-- main color -->
<item android:bottom="1.5dp"
android:left="1.5dp"
android:right="1.5dp">
<shape >
<solid android:color="#color/white" />
</shape>
</item>
<!-- draw another block to cut-off the left and right bars -->
<item android:bottom="5.0dp">
<shape >
<solid android:color="#color/white" />
</shape>
</item>
</layer-list>
Now define same in your EditText like this ..
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.vivektest.MainActivity" >
<TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
<EditText
android:background="#drawable/edit_text_style"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/et_main"
android:imeOptions="actionSearch"
android:singleLine="true"
/>
</RelativeLayout>
Hope it helps!
This is the best tool that you can use for all views and its FREE many thanks to #Jérôme Van Der Linden.
The Android Holo Colors Generator allows you to easily create Android components such as EdiText or spinner with your own colors for your Android application. It will generate all necessary nine patch assets plus associated XML drawable and styles which you can copy straight into your project.
http://android-holo-colors.com/
UPDATE 1
This domain seems expired but project is open source you can find here
https://github.com/jeromevdl/android-holo-colors
try it
this image put in background of EditText
android:background="#drawable/textfield_activated"
UPDATE 2
For API 21 or higher, you can use android:backgroundTint
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Underline color change"
android:backgroundTint="#android:color/holo_red_light" />
Update 3
Now We have with back support AppCompatEditText
Note: We need to use app:backgroundTint instead of android:backgroundTint
<android.support.v7.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Underline color change"
app:backgroundTint="#color/blue_gray_light" />
Solution for spinner style:
Create a custom adapter with a custom layout for your spinner.
Spinner spinner = (Spinner) findViewById(R.id.pioedittxt5);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.travelreasons, R.layout.simple_spinner_item);
adapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
R.layout.simple_spinner_item
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
style="#style/spinnerItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee" />
R.layout.simple_spinner_dropdown_item
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
style="#style/spinnerDropDownItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="?android:attr/dropdownListPreferredItemHeight"
android:ellipsize="marquee" />
In styles add your custom dimensions and height as per your requirement.
<style name="spinnerItemStyle" parent="android:Widget.TextView.SpinnerItem">
</style>
<style name="spinnerDropDownItemStyle" parent="android:TextAppearance.Widget.TextView.SpinnerItem">
</style>
Taken from here
I am trying to use the open source antennapod application as a reference for building my android application. I am using ActionBarSherlock and want to create a button at the bottom of my layout that extends from side to side with no padding. It should look like this:
My Styles.xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.Application.Light" parent="#style/Theme.Sherlock.Light">
<item name="attr/non_transparent_background">#color/white</item>
<item name="attr/borderless_button">#drawable/borderless_button</item>
</style>
</resources>
borderless_button.xml looks like this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape android:shape="rectangle">
<solid android:color="#color/selection_background_color_light" />
</shape></item>
<item android:state_focused="true"><shape android:shape="rectangle">
<solid android:color="#color/selection_background_color_light" />
</shape></item>
<item><shape android:shape="rectangle">
<solid android:color="#android:color/transparent" />
</shape></item>
</selector>
attrs.xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="borderless_button" format="reference" />
<!-- Used in itemdescription -->
<attr name="non_transparent_background" format="reference" />
</resources>
My Manifest has this:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Application.Light" >...</>
My layout is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/footer"
style="#android:style/ButtonBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<Button
android:id="#+id/butConfirm"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Search" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/queryString"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_margin="8dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="What would you like to search for?" />
<EditText
android:id="#+id/etxtQueryString"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/queryString"
android:layout_margin="8dp"
android:hint="Enter Query"
android:inputType="textUri" />
</RelativeLayout>
</RelativeLayout>
What it ends up looking like:
I just need one button but still want it to cover the whole width of the screen.
Here is the link to the source code I am using as a guide.
https://github.com/danieloeh/AntennaPod
Any help would be awesome!
Thanks
<Button
android:id="#+id/butConfirm"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Search"
android:background="#null"/>
This should do the trick!
I am trying to apply a transparent background to my row when it is pressed in my ListView. I create the file list_selector.xml like this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#drawable/argb80804040" />
</selector>
and in my news_item.xml, I define the back ground as follow:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/list_selector">
<ImageView
android:id = "#+id/img"
android:layout_width="95dip"
android:layout_height="75dip"
android:layout_alignParentLeft = "true"
android:paddingTop="10dip"
android:layout_marginLeft="10dip"
android:paddingBottom="10dip"
android:src="#drawable/no_news_image_small" />
<TextView android:id="#+id/title"
android:layout_gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_weight="1.0"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textStyle="bold"
android:paddingTop="5dip"
android:layout_marginLeft="110dip"
android:textColor="#21B6EF"
android:singleLine="true" />
<TextView android:layout_gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_weight="1.0"
android:layout_height="wrap_content"
android:layout_marginLeft="110dip"
android:textSize="10sp"
android:id="#+id/description"
android:layout_below="#id/title"
android:paddingBottom="10dip"
android:layout_marginBottom="5dip"
android:textColor="#fff"/>
</RelativeLayout>
However, it displays as solid color instead of ARGB color. My drawable is define as follow:
<resources>
<item type="drawable" name="transparent_orange">#64ff7b00</item>
<item type="drawable" name="argb80804040">#80804040</item>
<item type="drawable" name="argb40000000">#40000000</item>
<item type="drawable" name="argb80408040">#80408040</item>
</resources>
Do I need to do something else to get aplha color working? I am trying on my own device (motorola defy), and i am also using another application that uses the same alpha color and the color appears ok in this application, but in mine, it doesnt.
Many thanks for any response
T
I don't really understand what do you want to achieve but my proposal will be
Define your colors in res/values/colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="transparent_orange">#64ff7b00</color>
...
</resources>
Then you can define a drawable to be used as a background like this in res/drawable/test.xml:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#color/transparent_orange" />
</shape>
Finally, you can use the resulting drawable as an attribute of the target container with
android:background="#drawable/blue_linear_gradient"