How to add watermark in android widget EditText? - java

Please provide the implementation of watermark text in EditText widget of android,even after Googling it, but cannot find proper solution!

If by "watermark text" you mean the text which appears in the field when it is empty, then use the attribute android:hint="My Text" in the layout or programmatically call setHint( "My Text" ) on your EditText object.

You can add a layout make its height and width fill_parent and make background transparent and add a TextView as a water-mark in this layout.
I hope it can work.

Related

Hide the text on a button in android?

Please tell me how to hide the text on a button in android.
When I try this code, the button is hidden but I just want to hide the text on the button.
Button b= (Button)findViewById(R.id.follow);
b.setVisibility(View.GONE);
Please tell me how to solve this.
Thank you.
I have a suggestion if you want to setText to a button but don't want to show it.
Just set the text in the xml
android:text="TEXT"
then make font to 0
android:textSize="0sp"
text exist but can't be seen.
On your button use mButton.setTextScaleX(0); so the text will be hidden and to show use mButton.setTextScaleX(1);
If you just want to hide the Text and not the Button b.setVisibility(View.GONE) will not work.
It will hide the button itself and also button will not occupy any space in your layout as you are using View.GONE.
Using b.setText("") should help you setting just an empty text on Button.
May be you need to call invalidate()to refresh the UI.
First take backup of existing text on your button then clear button text to hide text. And to show text again reuse backup text :
Button b = (Button)findViewById(R.id.follow);
//Backup button text
String mButtonText = b.getText();
//Now hide text
b.setText("");
//To show text again
b.setText(mButtonText);
You can set the button text to just be blank instead of trying to hide the button.
Button button = (Button)findViewByID(R.id.ButtonID);
button.setText(" ");
This will allow you to change the text of the button within your source, so you will be able to change the button text when an event happens or even just set the button text to blank when it is created.
Button.setTextColor(getResources().getColor(android.R.color.transparent));
This will make the text transparent/hidden. It will keep the original size of the button and keep the original text.
on your xml. remove the android:txt=" " on your button.
Try this
<Button
android:text="TEXT"
android:textColor="#00000000"/>
general info:
#<alpha><red><green><blue>
all in hexadecimal 00 to ff

Android - Change a layout attribute on a button click

I have a problem here.
I have a large text, that doesn't fit in the screen... So in the layout XML I have put this string:
android:ellipsize="end"
Ok, but now I want to make this TextView clickable and when I click it, I want to change the layout XML code to:
android:ellipsize="marquee"
So the text roll and people will read it.
I've searched lots os questions but none has answered that, just for 'drawable' things.
Thanks!
Use
textView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
on textView Click.

Relativelayout circual dependancy

I'm trying to create my android app for a lot of different devices so I'm trying to avoid using fixed heights and width and instead using the property WRAP_CONTENT.
Now I need to create a textview on top of a button and align that to the bottom. However the documentation states that you can't use WRAP_CONTENT in combination with ALIGN_PARENT_BOTTOM (which is obvious). Is there another way to achieve this?
The structure is something like this. A RelativeLayout which wraps a button and a textview.
RelativeLayout fl = new RelativeLayout(this);
fl.setLayoutParams(relativeWrapContentParams);
fl.addView(filterBtn);
fl.addView(filterCaption);
The buttons are also created dynamically so theres no xml. Instead the buttons are created in java code.
Also is this a good way of programming for multiple resolutions? Or is it ok to use fixed heights because then the problem is easy to fix and I can just give the relativelayout a fixed height and align its children with ALIGN_PARENT_BOTTOM
See this link this article is the bible for the newbies in android.
Now coming to your question you don't need to use relative layout just for this purpose
you can use linearlayout with vertical orientation place text and then button.
and you need to place this linearlayout inside relative layout with property alignparentbottom=true.
in such way you can have this layout of text and button at the bottom of the screen

How to add clickable widgets in EditText at current position

I guess the title of the question is clear enough. What I want to do is add clickable widgets like Lable or Button or TextView in an EditText which already has some text in it. These widgets should get appended to the text.
As I don't know the exact number of the widgets to be added at design time, it won't be possible to do it in xml. I must do it in Java.
Thanks in advance.
Views just can be added to ViewGroups and EditText is not a ViewGroup, so you can't do that with default EditText widget, and you can write your own custom View to implement that.
this is the android documentation about custom views, and taking a look at this can be useful too.

Android Row becomes Unclickable with Button

I have a listView, where each row has a button in the row layout. However, this seems to make the row itself unclickable. How can I make both the button and row clickable?
Thanks.
You need to set itemsCanFocus on the list like this:
mList.setItemsCanFocus(true);
To make the button clickable. Then you will need to use your own adapter and in getView return a view which is Clickable and focusable. You will also lose the default highlight states so you need to put them back in with the background resource. So do this:
view.setClickable(true);
view.setFocusable(true);
view.setBackgroundResource(android.R.drawable.menuitem_background);
to your view before returning your view.
Whenever I see posts concerning the android:focusable and android:clickable attributes, I always see them being both set to the same value at once. I figured there must be a reason if they are two separate attributes instead of being one.
It turns out that a much better way of achieving your desired behavior is to set
android:focusable="false"
or
yourButton.setFocusable(false)
on the Button in your View. Once you do that, you'll be both able to set an OnClickListener on the Button, and a click on the row will fire the onListItemClick() method in your OnItemClickListener.
Try to set your widgets to non clickable and non focusable in xml,the click on items will work normally and also the click on button will work normally.
android:clickable="false"
android:focusable="false"
Hope this helps.
Unfortunately I don't think that is possible. You ListView row can either have focusable widgets, like a button, or be clickable, not both. See link.

Categories

Resources