I am not sure if I have a bug inside my head ,or it is inside the android's EditText .
I have a simple EditText .
<EditText
android:id="#+id/name_value"
android:layout_width="0dp"
android:layout_height="#dimen/feedback_form_comment_box"
android:layout_weight="6"
android:background="#drawable/black_border"
android:padding="#dimen/feedback_form_padding" />
When I run this , I see a normal edittext with a shapedrawable (just a black border) on the screen. Perfect.
I need to set the gravity now . Because the cursor starts in the middle of the text area. I want the cursor to be displayed in the start of the edittext. So I set the gravity like this .
<EditText
android:id="#+id/name_value"
android:layout_width="0dp"
android:layout_height="#dimen/feedback_form_comment_box"
android:layout_weight="6"
android:gravity="top|left"
android:background="#drawable/black_border"
android:padding="#dimen/feedback_form_padding" />
Now mysteriously , the bottom border of the edittext goes away .
This is the shape drawable I am using .
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<!-- Solid will define the color of our shape's body -->
<solid android:color="#color/white" />
<!-- Stroke will define the border of our shape-->
<stroke
android:width="1dp"
android:color="#color/black" />
</shape>
What's going on?
bro!
i also come across such a question. It happens on some android pad devices.
After a long test, i find that it was the padding of textview which caused this. Not only the shape drawable but also img background will cause this.
A better way is to set padding for textview manually.
If have time,i will continue to check the source code for what have cause this.
Related
So, I created a TextInputEditText with oval edges using this code:
XML Oval Shape:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="50dp"/>
<stroke android:width="1dp"
android:color="#44433A"/>
<solid android:color="#FFF"/>
here is the TextInputEditText:(I know the style should be inside the style.xml file)
<android.support.design.widget.TextInputEditText
android:id="#+id/Ti1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginEnd="60dp"
android:layout_marginTop="10dp"
android:background="#drawable/oval"
android:elegantTextHeight="true"
android:hint="#string/hint_Note"
android:inputType="textCapSentences|textMultiLine"
android:maxLines="8"
android:paddingBottom="5dp"
android:paddingEnd="50dp"
android:paddingStart="20dp"
android:paddingTop="5dp"
/>
here you see that when a person goes to the 2nd line it expands to a maximum set as 8 lines,but my problem here is when it expands it starts forming a full oval but i want it to become this:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="5dp"/>
<stroke android:width="1dp"
android:color="#44433A"/>
<solid android:color="#FFF"/>
my first assumption was that I should change the background when the lines expand further than 1 line, but I don't know if this is a good solution or not,is there a better solution, I am trying to mimic the new Whatsapp bottom EditText behavior when it comes to expanding the EditText.
I am able to reach this shape on the edges
as the line expands the edge creates a small vertical line between the round edges of the edittext
as you might see that upon reaching 3 lines the line is still increasing in length on both left and right sides
another example upon reaching 4 lines
but when I try to write something in my TextInputEditText it expands but it does not create a straight vertical line on the left and right edges, it starts to form an oval.
I have a static xml layout with a background color (looks like a printed label) that I want to show at an angle. The issue I have is the edges of the background look like they were rendered in the 1980s (jagged - NOT anti-aliased).
How can I get a textview that looks like a label at an angle and have it look decent (i.e. anti-aliased)?
Layout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:maxLines="1"
android:singleLine="true"
android:text="Sample Text"
android:textAllCaps="true"
android:textColor="#ffffff"
android:textSize="12sp"
android:background="#3db8eb"
android:rotation="-3"
android:paddingTop="1dp"
android:paddingBottom="1dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"/>
</LinearLayout>
How it looks:
Per my related answer, setFilterBitmap didn't quite work for me. Partially because I was using a 9patch background instead of a color.
Approach #1: disable hardware acceleration on the view
What did work was disabling hardware acceleration for the view in question and its parent (either one, alone, did not work):
private void fixAntiAlias(View viewFromThe80s) {
if (Build.VERSION.SDK_INT > 10) {
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG | Paint.FILTER_BITMAP_FLAG);
viewFromThe80s.setLayerType(View.LAYER_TYPE_SOFTWARE, p);
((View) viewFromThe80s.getParent()).setLayerType(View.LAYER_TYPE_SOFTWARE, p);
}
}
edit: [2/2/17] : I ran into this problem again but this time needed to fix it only via resource file differences, rather than code/logic differences
Approach #2: XML-based fix
Sometimes, you don't have the luxury of editing the view logic. For instance, in my case, two views share the same RecyclerView.Adapter and one has a rotated view and the other doesn't. I need the view/adapter logic to remain unchanged but the XML layouts and resources can diverge. So I took this approach:
1. Make a shape with a transparent border
src/main/res/drawable/background_rotatable_color.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- transparent 1px border -->
<item>
<shape>
<solid android:color="#android:color/transparent"/>
<size android:width="16dp" android:height="16dp"/>
</shape>
</item>
<!-- main color : inset by 1px so the transparent layer below shows so that when antialiasing is done, it blends better -->
<item android:top="1px" android:right="1px" android:left="1px" android:bottom="1px">
<shape>
<solid android:color="#color/red"/>
</shape>
</item>
</layer-list>
2. Apply shape and (optional): use tinting to set it to desired color
src/main/res/layout-land/item_product_details.xml
<TextView
android:id="#+id/text_savings_banner"
. . .
android:background="#drawable/background_rotatable_color"
android:backgroundTint="#color/blue_accent" /> <!-- optional but handy if you need to do this in a lot of places with different colors -->
After trying a few different things, I finally found something that works albeit a bit convoluted. Here's how to get smooth edges on a rotated textview with a solid color background:
Step 1: Create a drawable resource with the color (i.e. ColorDrawable or Shape like a rectangle)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#color/blue" />
</shape>
Step 2: Set the background to that drawable.
<TextView
android:id="#+id/my_textview"
...
android:background="#drawable/blue_rectangle" />
Step 3: In code call:
TextView textView = (TextView)findViewById(R.id.my_textview);
textView.getBackground().setFilterBitmap(true);
I'm trying to change the color or disable the highlight of the text when writing on my EditText.
How can I do that?
How can I set rounded borders to the highlight?
I want to do that becouse, when I start writing on my EditText the highlight overlap the rounded corners of my EditText, and it looks bad.
Code for background color and corner rounded of my EditText:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="5dp" />
<solid android:color="#FFFFFF"/>
</shape>
Code of my edittext:
<EditText
android:id="#+id/editTextUsuario"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/propertieseditextlogin"
android:ems="10" >
<requestFocus />
</EditText>
There are 2 examples of my problem:
Image - Gray highlight
Image - Overlap rounded corners
Try adding this attribute to your editText to disable highlighting.
android:defaultFocusHighlightEnabled="false"
You can create highlight with rounded corners programmatically by creating custom View extending edit text, but that's really lot of work.
Also have a look for material design, with this library you can implement edit text with rounded corners pretty easily.
To disable the highlight of the edittext, you can just write following.
android:background="#00000000"
Give the editext a padding using android:padding or set the background attribute to white
Solution of your second problem
Give padding to your EditText
Example:-
<EditText
android:id="#+id/editTextUsuario"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/propertieseditextlogin"
android:paddingLeft="6dp"
android:ems="10" >
<requestFocus />
</EditText>
I am gonna to create the a alert dialog box in android with rounded shape.
I follow many threads in this site. Create a shape.xml and place it drawables
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="5dp" android:color="#FF0000" />
<corners android:bottomRightRadius="20dp" android:bottomLeftRadius="20dp"
android:topLeftRadius="20dp" android:topRightRadius="20dp"/> <solid android:color="#FFFF00"/>
And apply the above shape to the linearlayout.
layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#android:color/transparent" >
<LinearLayout android:layout_width="200dip"
android:layout_height="60dip"
android:orientation="vertical"
android:background="#drawable/shape">
</LinearLayout>
However, there is still have a rectangle border and back color outside the dialog box. That is not what I want.
I have search for a long time I dont know how to fix it.
I aimed to make it transparent outside the corner of the dialog box layout. Thank you so much!
Screen Shot: http://postimg.org/image/3xbnmquyt/
For the shape you want I found the default one on Android Studio, this:
android:background="#drawable/abc_menu_dropdown_panel_holo_light"
Apply it to your LinearLayout, It is exatcly what you're talikng about and you don't need to create other xml files in the drawables. To see how It looks like see my answer here:
Android View shadow
Hope I helped you.
Remove the stroke tag because it is used for creating the border. Also you shouldn't use gradient and solid together because they exclude one another.
http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape
I am using following for strike text.
viewHolder.price_red.setPaintFlags(viewHolder.price_red
.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
Its working but I want to increase size of strike through line.
Can anybody help me how to increase size of line ??
You can't change the thickness of the strikethrough line.
As you can see from the docs its just a flag. Either on or off.
There are a couple of options though (more hacks than solutions):
Make the text bold or stroke it. This will automatically stroke the strikethrough too which will make it more visible
Manually draw the line with drawLine. (This would be really difficult to do accurately though)
This can not be achieved directly as Android doesn't provide any API for the same.
Now, you will have to go Custom way to draw the thicker line.. 1) DrawLine 2)Use Line Image over EditText
I have tried using a EditText and a ImageView under a RelativeLayout and it worked quite nicely for me.
XML Code :
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/etStrike"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="Strike Thru Text Here"
android:textColor="#color/blacktext"
android:textSize="20sp" />
<ImageView
android:id="#+id/ivStrike"
android:layout_width="wrap_content"
android:layout_height="6dp"
android:layout_centerInParent="true"
android:background="#color/blacktext" />
</RelativeLayout>
JAVA Code :
EditText etStrike = (EditText)findViewById(R.id.etStrike);
ImageView ivStrike = (ImageView)findViewById(R.id.ivStrike);
float textSize = etStrike.getTextSize()/2;
int textLength = etStrike.getText().length();
int totalLengthApprox = (int) (textLength * textSize)-textLength;
int height = 6; // YOUR_REQUIRED_HEIGHT
RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(totalLengthApprox,height);
param.addRule(RelativeLayout.CENTER_VERTICAL|RelativeLayout.ALIGN_PARENT_LEFT);
param.setMargins((int)textSize, 0, 0, 0);
ivStrike.setLayoutParams(param);
I have tested only a few TextSize and Device Resolutions and most important this can work only for singleline EditText for multiline the logic becomes more complex.
Here is how to go about it: use a layer-list and place as your textview background. Here i am assuming your textviews background is white (#FFFFFF)
create in the drawables folder a file called
strikethru.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#FFFFFF"/>
</shape>
</item>
<item>
<shape android:shape="line">
<stroke android:width="1dp"
android:color="#8d8d8d"/> <!-- adjust color you want here -->
</shape>
</item>
</layer-list>
then in your textview do this:
<TextView
android:id="#+id/tv_toolbar_prod_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="3dp"
android:text="1,290 B"
android:background="#drawable/strikethru_line"
android:textColor="#070707"
android:textSize="13sp" />
the padding right of 3dp makes the strike through more evident.