I want to add an image to the left of the text in the button. So I used the below piece of code
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:drawableLeft="#drawable/ic_login"
/>
After doing this, the Layout Editor shows me this
But since there's no android:drawableStart Android Studio complains to me about this and when I add it. The final code looks like this:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:drawableLeft="#drawable/ic_login"
android:drawableStart="#drawable/ic_login"/>
and now the button looks like this -_-
I know, one solution could be to just ignore the warning but I don't think that's what's recommended.
P.S. If I just do drawableStart then also no image is shown.
What should I do, am I missing something crucial?
You can just get rid of the warning in this case by doing (Windows) alt+enter and then ignore it for that specific view
That will add a attribute so you'll still know it's ignored on purpose when looking at the view.
I think it just need to set layout direction :
android:layoutDirection="ltr"
it will be automaticlly replace
Related
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.
So I would like to see my layout preview with the fields filled with something like default placeholders but if I use bindings the settext attribute is already used and the fields are showing empty since there is no info from the models yet.
<TextView
android:id="#+id/tv_user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:gravity="center"
**android:text="#{showBlueportSpotViewModel.name}"**
android:textAllCaps="true"
android:textSize="20sp"
android:textStyle="bold"/>
I tried this:
android:text="#{showBlueportSpotViewModel.name ?? #string/blueport_placeholder_name}"
but I still see the view empty.
Do you guys any workaround? I guess once a workaround is found, it can be used to ImageView and src for example and etc..
Thank you!
You can use the tools attribute to define properties that will appear in the layout preview but will not appear when you run the app.
Add the following to your root view:
xmlns:tools="http://schemas.android.com/tools"
Then use the tools attribute to define text that will only appear in the layout preview:
tools:text="placeholder text"
The tools attribute is very useful when mocking up views in the editor. All of the tools attributes are stripped when the app is packaged. More information here: http://tools.android.com/tech-docs/tools-attributes
I found a workaround
I added
xmlns:bind="http://schemas.android.com/apk/res/android"
to the layout
and just having duplicated declarations in the view like:
android:text="#string/blueport_placeholder_name"
bind:text="#{showBlueportSpotViewModel.name}"
or
android:src="#{showBlueportSpotViewModel.blueportImageDrawable}"
bind:src="#drawable/android_menu_header"
I don't really know if this has secondary wrong consequences so I won't accept this answer until somebody can comment and say if it is okay.. Thanks!
After some pretty thorough googling I still cannot figure out what the the little graphic that's displayed under the text in and EditText View is called. I would also like to remove it either using XML or programmatically. The little graphic is the thing under the cursor in this image: http://1.bp.blogspot.com/-UAuOq0h4Vok/T8reinvaWPI/AAAAAAAABPc/N4yibXd3kZg/s1600/android%2Bedittext%2Btext%2Bchange%2Blistener%2Bexample.jpg . Sorry if this is a dumb question, but without the name of this little graphic feature I can't seem to find out anything about it.
It is the background drawable associated with the edittext. You can change it by manually setting the background to something yourself, such as
<EditText
android:background="#android:color/transparent"
...
/>
Try this..
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/hello"
android:background="#00000000"
/>
if you want transparancy just put 80 before the actual hash code.
#80000000
This will change any colour you want to transparent one.. :)
you probably have in your layout
android:minLines="2"
try to remove it
I am having one contact form in which I would like to add some icons to my edit text for a better look. I want to create EditText something like below.
I have EditText like below. And I got the result something like. I want the image to be absolutely on the left side as it is in the above image. I know that internally EditText is using Nine Patch image and i think that is why the result is some what different. Can anyone know how to resolve this?
<EditText
android:id="#+id/name"
android:layout_width="fill_parent"
android:layout_height="51dip"
android:hint="#string/name"
android:inputType="text"
android:drawableLeft="#drawable/name_icon_edittext" />
Instead of using android:drawableLeft="#drawable/name_icon_edittext", create separateImageView for the name_icon.
This way you have more control on placing it on the layout
Note: I am assuming your layout is RelativeLayout
if you want to add some space between you text and image then use'drawablePadding' property in xml
android:drawablePadding="10dp"
here is complete example how to use in edittext in xml file
<EditText
android:id="#+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/ic_left"
android:drawablePadding="10dp" />
You can use android:drawablePadding="10dp" property in the xml file.
There's no need to create separate imagview for the icon.
A bit old, but for future reference maybe:
I would do a 9-patch image myself with the appearance you want, keeping the proportions and all but the icon, so you can add it yourself (and reuse the background) with drawableLeft property of EditText. That way only the middle part of the image will be stretched but the rest will stay the same.
This is my XML for my check box:
<CheckBox
android:id="#+id/atm_checkbox"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#color/input_color" />
And it looks like this:
http://imageshack.us/photo/my-images/528/47342915.png/
This is what i found on internet:
<CheckBox
android:id="#+id/chkAndroid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/chk_android"
android:checked="true" />
which looks like this
how to change my checkbox to look like the one i found on internet.
As my rep is <10 i cant upload image of my checkbox, or can anyone help me how to style checkbox to make it look better
I think both the xmls have similar code, but why are they looking so different?
If you want custom the look of checkbox see this tutorial and find everything.
By the way, the checkbox from your link is for Android3.0 and above.
CheckBox derive from Button class, so you can set a background image like button. See this link, may be it is what you are looking for.
If you want a clean design without codes, use:
<CheckBox
android:id="#+id/checkBox1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:drawableLeft="#android:color/transparent"
android:drawablePadding="10dp"
android:text="CheckBox"/>
The trick is to set colour to transparent for android:drawableLeft and assign a value for android:drawablePadding. Also, transparency allows you to use this technique on any background colour without the side effect - like colour mismatch.