This is what i want to make for my textview. I have a 9 patch image . But i have no idea how can i convert this png image into the folded corner background for the textview.Many of you may have faced this problem and came up with a solution. So, please share how did you solved yours.
Heres the solution for you:
<TextView
android:id="#+id/yourTextViewWidget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/your_9_patch_image"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:text="Testing News" />
Let me expalain here: Setting the 9 patch image as the background of the textview and putting the padding to the textview will create the above image like background for your textview.
Related
Hello Guys I need some help in creating Imagebutton. I created custom button on PS and then saved it in PNG format with transparent background. After that i patched my image with 9patch. Now i am using that image as a button in my layout but the image is showing colored background corners. I tried alot of things but its not removing.
Here is my XML
<ImageButton
android:id="#+id/mybutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:src="#drawable/registerbutton"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="123dp" />
Keep the background attribute as #null like this :
android:background="#null"
If still you are getting that corner, it might be from the png file that you are using.
This is an example of what i get from #null
Probably the ouput of "9patching" operation added corners. Open the file and check if there are corners or not.
If that won' help, try switching android:src attribute with android:background attribute.
And u can make .png button online using this site
I am sorry to ask this silly question but I am unable to set textcolor property in android xml.
This is my code:
<TextView
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textStyle="bold"
android:textColor="#color/TextColor"
android:textSize="35dp"
android:layout_gravity="center_horizontal"/>
and color :
<color name="TextColor">#00427E</color>
I am able to see this color change in preview screens but not in real device.
My .gradle includes:
compile 'com.android.support:appcompat-v7:23.1.1'
Please help
You can use Programmatic Way
setTextColor(Color.parseColor("#00427E"));
Or
setTextColor(getResources().getColor(R.color.TextColor);
Try Textview xml code
<TextView
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textStyle="bold"
android:textColor="#00427E"
android:textSize="35sp"
android:layout_gravity="center"/>
IF don't Work this code use This Java side
setTextColor(Color.parseColor("#00427E"));
Sometime it happen may be if your Android Studio have lot of cache. so try to clean cache.
go to File > invalidate Caches / Restart click on it. may be solve your problem.
I face same problem. I think it is device specific problem. I tested in nexus,and motorola devices its working fine but pick a device default color in MI devices. To resolve this issue set the text color programaticly.
TextView textView = (TextView) findViewById(R.id.yourid);
textView.setTextColor(ContextCompat.getColor(this,R.color.TextColor));
from what you have written, the implementation should work:
android:textColor="#color/TextColor"
is the attribute which changes the color of the text.
What i would suggest is, check the background color of the layout in which this TextView is placed. It is possible that the background color is the same as the color you are trying to set on the TextView, that is why you are not able to see the difference.
If you want to be double sure, set a black or white color on the TextView and see if it appears on as desired on screen.
If you still do not get the desired result, paste the full xml here so that we have a better idea of what's going on.
How can I edit text shape like this.
I mean that right rounded corners and exact same shape. As I understood 9 patch doesn't help me with that.
9 patch will be best way in your situation, create 9 patch and set it as background of your EditText.
Here i am giving you sample image, you can try with it.
editText.setBackground(R.drawable.edt_bg);
This ninepatches will help you. just apply this ninepatch images as backgroud of the editText
You have to create background image for your EditText. For the other layout, you have to create layout which will look like this. Its not the exact xml but showing you the idea.
<RelativeLayout layout_width="match_parent" layout_height="50dp">
<EditText layout_width="wrap_content" layout_height="wrap_content"
android:background="#drawable/editTextBackground" layout_alignParentLeft="true" layout_marginLeft="10dp">
<ImageView layout_width="wrap_content" layout_height="wrap_content"
centerVertical="true" marginLeft="15dp"
android:background="#drawable/smily" />
<ImageView layout_width="wrap_content" layout_height="wrap_content"
centerVertical="true"
alignRight="#id/editTExt"
android:background="#drawable/camera" />
<ImageView layout_width="wrap_content" layout_height="wrap_content"
centerVertical="true" marginLeft="15dp"
alignParentRight="true"
android:background="#drawable/mic" />
</RelativeLayout>
Hope this gives you the idea.
I'd like to have an image in a button with text and I've already have it. But the problem is that my image is with some " grey background colour" (as you can see below) that I would like to remove.
In a normal situation I would use android:background="#null" and it would solve it, but I'm using as background a template to my button.
<Button
android:drawableLeft="#drawable/profile_32"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp"
android:textColor="#color/yellow3"
android:background="#drawable/buttons2"
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="#string/button_profile"
android:textSize="18dp"
android:textStyle="bold"
android:id="#+id/buttonProfile"
/>
Does anyone know any other way to remove that grey background color from the image? Thanks.
Is the grey actually part of the image? If not you could try background:"#android:color/transparent"
If the grey background is part of the profile_32 image, there is not an easy way to remove it in Android. You will need to have the image re-exported or use an image editing program to remove the background.
Yes, use an ImageButton and just add
android:background="#00000000"
or
android:background="#null"
to your Button.
The first 2 "0" is alpha, "00" = trasparent
I am having some weired problem with 9-patch image in my android app.
I want to make a line across a screen with a simple png. After creating 9-patch from it I've simply added it as a drawable to ImageView container. Unfortunatelly it doesn't want to stretch and still has this same dimmensions. Because I've never used 9-patch png I have no idea what am I doing wrong and also searching in Google is not so helpful, because there are only info, how you can make one, now how you can use it.
This is my code fragment from xml file:
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/testpng" />
and this is a image I want to add:
Well, if it's just a simple line,you wouldn't need a 9 patch...
Just use a View, give it a color as a background and give it a 1 px dimension:
<!-- Horizontal line -->
<View
android_layout_width="match_parent"
android_layout_height="1px"
android:background="#ffff"
/>
<!-- Vertical line -->
<View
android_layout_width="1px"
android_layout_height="match_parent"
android:background="#ffff"
/>
For the Shadowed line:
I'm using it so:
<View
android:layout_width="match_parent"
android:layout_height="2px"
android:layout_centerVertical="true"
android:background="#drawable/line_h"
/>
and this is line_h.9png, as small as I could make it (6*4 px) ;)
Now, this doesn't show in my graphical layout editor, but it does at run time!
Check that the extension of your file is .9.png. If it isn't, it's not recognized as a 9-patch.
I found an answer to my question. The missing thing was one line of code android:scaleType="fitXY".
Now it looks like this
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/testpng" />