Strike through Multiline TextView [duplicate] - android

This question already has answers here:
Is there an easy way to strike through text in an app widget?
(20 answers)
Closed 7 years ago.
This in not a duplicate question, i found some question but they were not having satisfied answers, answers were not available for multiline textviews.
I have already checked this below link but they were not enough useful:
Is there an easy way to strike through text in an app widget?
I want to create a line across the center of a TextView (striked TextView), but I want to do it in XML layout, not in the Java code.
I have already achieved this result through the use of JAVA code as such:
myTextView.setPaintFlags(myTextView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
I would like the same result, but in the below XML code:
<TextView
android:id="#+id/myTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
Thanks again.

<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:text="XYZ"
android:background="#drawable/line"/>
line.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke android:width="1dp"
android:color="#android:color/white"/>
</shape>
Try this !
EDIT
The above code will work only for single line text.
For Multi line text use below code :
<string name="strike_text">
<strike>sample TextView \nSecond line of TextView</strike>
</string>
And use it as
android:text="#string/strike_text"

Easiest way would be to use an image.
create image with horizontal line and transparent background and set it as background of TextView
android:background="#drawable/strike_through"
Or
Create an xml file which will draw a line and set it as background of your TextView
<shape android:shape="line">
<stroke android:width="2dp" android:color="#ffffff" />
</shape>

The way to do this in xml is to create a drawable of the strike and set it as the background of the TextView. An example of the drawable would be:
<item android:state_pressed="false">
<shape android:shape="line">
<stroke android:width="2dp" android:color="#ffffff" />
</shape>
</item>

Related

How can I make this type of custom EditText UI?

I am trying to put borders on edit text and put a label on it. I have tried this one.
<stroke
android:width="2dp"
android:color="#color/colorPrimary"/>
<corners android:radius="15dp"/>
But I want the following one. Initially it will look like this.
After clicking it will be like this.
Would you please help?
use the material design Outline Box style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
this link may help you http://qaru.site/questions/1688917/custom-textinputlayout-android
As #ZahoorSaleem said, you can use the MaterialComponents for that.
You will need to add the design support library to your build file.
The layout would (simplified) look like this:
<TextInputLayout
android:hint="Label"
style="style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<TextInputEditText />
</TextInputLayout>
put the below code in drawable and use this attribute in edittext
android:background="#drawable/nameofdrawablefile"
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#CC0505"/>
<stroke android:width="2dp" android:color="#CC0505" />
<corners android:radius="5dp" />
</shape>

How to put a border in an EditText? [duplicate]

This question already has answers here:
How to have EditText with border in Android Lollipop
(6 answers)
Closed 5 years ago.
anybody could tell me, how to put a border in an editText in AndroidStudio?
for example a square in an editText.
It's so easy bro
First step create an shape.xml in your directory drawable
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1dp"
android:color="#android:color/black"/>
</shape>
Second step create your editext in your layout.xml and put background with the shape that you created above
<EditText
android:id="#+id/edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/shape"/>
It's all
just try this one,
first create one XML file, inside drawable folder (use new drawable xml) and add this lines
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"/>
<solid android:color="#000000"/>
<stroke
android:color="#ffffff"
android:width="05dp"/>
<corners android:radius="20dp"/>
then add this line inside Your edittext property
android:background="#drawable/(file_name)"
i don't know what your expecting, maybe it will help you

How to change the color of line at the bottom in EditText? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I know this question has been asked before but that solution are not working in my case. I want to change edit text bottom line color and tried the solution from other links to add this line to theme in styles.xml
<item name="colorControlNormal">#c5c5c5</item>
but somehow this is not working in my case. I tried changing base theme but still not working for me.
And I want to do this with all editext in my app, not just only one.
Are there any other ways of doing it??
Edit Style.xml under values folder.
<style name="Theme.App.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorControlNormal">#c5c5c5</item>
<item name="colorControlActivated">#c5c5c5</item>
<item name="colorControlHighlight">#c5c5c5</item>
</style>
create a file edittextborder.xml in drawable folder and write
?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#ffffff" />
</shape></item>
</selector>
and Set this file as:
android:background="#drawable/edittextborder"
in editText.
This can be changed in xml by using:
android:backgroundTint="#color/blue"
Solution follows as below-
I want u to visit Android Holo Colors Generator.
Provide a Theme name and select a color u want.
Select the components u want to change the color. In ur case its Edittext.
Finally click on Download Zip.
Extract the Zip and use it in ur proj.
Try this one,
.xml file
<?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:layout_margin="5dp"
android:padding="5dp">
<EditText
android:id="#+id/text_to"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/customborder" //.xml file for edittext
android:clickable="true"
android:padding="5dip"
android:text="Text_to"
android:textColor="#color/black"
android:textSize="#dimen/font_normal_size" />
</LinearLayout>
customborder.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="2dp"
android:topRightRadius="0dp"
android:bottomRightRadius="0dp"
android:bottomLeftRadius="0dp" />
<stroke
android:width="1dp"
android:color="#android:color/white" />
</shape>
I preferred to use 9 patch images for edit text custom color.
Android 9 patch generator online
This is awesome online tool generator for all widgets.Android Holo colors
generate and download for every dpi folder. and apply it using background.
Using Rohit's answer and a hack provided from this link Android Bottom Stroke only.I was able to achieve my desired behaviour. Here is the code for drawable folder file.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" >
<solid android:color="#android:color/transparent" />
</shape>
</item>
<item android:top="-2dp" android:right="-2dp" android:left="-2dp">
<shape>
<solid android:color="#android:color/transparent" />
<stroke
android:width="1dp"
android:color="#FFFFFF" />
</shape>
</item>
</layer-list>

Rounded corners of Button [duplicate]

This question already has answers here:
How to make the corners of a button round?
(19 answers)
Closed 9 years ago.
Basically, from what I have noticed is that when you add a background color to a button, the rounded corners element disappears, so basically there are no rounded corners. But when I don't have a background color, the corners of the button are round.
I don't understand whats happening.
Please Help
The border is part of the default background drawable so you have to replace it by one that contains borders also if this is what you want.
Take the default background resource and edit it to have some color.
Alternatively you can use
button = (Button) findViewById(R.id.button);
button.getBackground().setColorFilter(color, Mode.SRC_ATOP);
which perhaps gives something closer to what you expect.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_enabled="false">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp" android:shape="rectangle">
<solid android:color="#FFb888"/>
<corners android:bottomLeftRadius="15dp" android:bottomRightRadius="15dp" android:topLeftRadius="15dp" android:topRightRadius="15dp"/>
</shape>
</item>
<item android:state_enabled="true" android:state_pressed="true">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp" android:shape="rectangle">
<solid android:color="#FFD488"/>
<corners android:bottomLeftRadius="15dp" android:bottomRightRadius="15dp" android:topLeftRadius="15dp" android:topRightRadius="15dp"/>
</shape>
</item>
<item android:state_enabled="true">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp" android:shape="rectangle">
<solid android:color="#FF8C00"/>
<corners android:bottomLeftRadius="15dp" android:bottomRightRadius="15dp" android:topLeftRadius="15dp" android:topRightRadius="15dp"/>
</shape>
</item>
</selector>
<Button
android:id="#+id/btn_add_list"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:background="#drawable/rounded_orange_button"
android:text="#string/action_new_list"
android:textColor="#color/white"
android:gravity="center"
android:textSize="18sp"
android:layout_marginTop="20dp"
android:layout_marginRight="10dp"
android:layout_alignParentRight="true"
android:onClick="doNewList"/>
You can save the above xml file that will be the background for your button in a file called rounded_orange_button.xml in the res/drawable folder. So it would be res/drawable/rounded_orange_button.xml. This will also give your button feedback to the user when they select it, follows the dsign guidelines from developer.android.com a little more closely but it is your preference. there are a million ways to skin a cat. Then reference what you created in the drawable folder inside your_layout.xml file by the second example. The color values are optional and can also be set from another resource file in the res/values/colors.xml if need be. Use the res/values/strings.xml for any strings you want displayed inside the button. Hope this helps. Also, the amount of the curve on the buttons can be adjusted by playing with the radius values in the
The background of the button is going to give you square corners. For a nice custom background, I would suggest making a background image and using as either the button's background or src. So your xml would look like:
android:src="#drawable/mybuttonimage"
android:bacgkround="#null"
or
android:background="#drawable/mybuttonimage"
I would test out both, as they can stretch your image differently.
Another option is to to create a shape in your res/drawable folder.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#33DDFF" />
<corners android:radius="4dp" />
</shape>

"How to pass a parameter into a drawable" or "Create button with gradient and changeable image"

I have a custom drawable in my android project that should be the background of a button. But each button should also support an icon AND a text.
What I tried so far is the following:
I have a drawable called "btn_background.xml"
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list >
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#ff0000"
android:endColor="#ee1111"
android:type="linear"
android:angle="90"/>
<stroke android:color="#ff0000"
android:width="1dip"/>
<size android:width="80dip"
android:height="40dip" />
</shape>
</item>
<item android:drawable="#drawable/btn_search"/>
</layer-list>
</item>
And in my layout file i use that like this:
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:background="#drawable/btn_background"
android:textColor="#ffffff"/>
This is getting me somewhere close... but there are two problems:
* The image is stretched across the whole button
* I can't just change the image in the layout file... so i would have to make a seperate btn_whatever.xml file for each icon?!?
The other solution that I tried was to use an ImageButton instead of an Button and set the background to my btn_background.xml .... this would make me able to select the image in the layout file... but then i can't give it a text....
I would be happy to hear about your solutions for my problem :)
Thanks a lot!
Try to use android:drawableLeft (or similar Top, Right, Bottom) attribute.

Categories

Resources