How to create a alertdialog using hyperlinks textview in android - android

I have a Text view in hyperlink,when i click the link i want to open the alert dialog.
How to do this.i knew Separately to create the Alert dialog ,but using hyperlink am getting struggle.
My code
policy.setText(Html.fromHtml("<a href>PasswordPolicy</a> "));

This involves a little trick, Use underline tag in strings.xml like below
<string name="tvideo"><u>Video</u></string>
Now set this in your TextView in the .xml
and setonclicklistener to that TextView and open your dialog.
Also note that output will be seen during run-time. I'm afraid it will not be visible in Graphical Layout.

for that you need to create custom dialog and its text property as linkify.
TextView myWebSite = new TextView(this);
myWebSite .setText("http://http://www.google.com/");
Linkify.addLinks(myWebSite , Linkify.WEB_URLS);

Related

How to change existing TextView style in action

I have some intent with set of TextViews and a Button. If user clicks the button and there is some error I want to change look of one TextView. E.g. change the border to red and make font bold. I wrote a style for it but I have not found method setStyle on the TextView. After some self study I realized that Android does not support setting the style programmatically. There are some workarounds, when you create the intent source. But my intent already exists, it seems odd to recreate it.
Could you tell me the proper way?
use the workaround and create the TextView again
forget the styles and use java methods to decorate existing TextView
something else
Changing the style of the textview directly does not work as you know. But you can create a second textview with other styles in your layout, which you can show up if needed.
Just add this xml attribute android:visibility="gone" to the second textview, so this second textview is not displayed at first, but available.
When you now want to change the style of your textview, you simple need to swap the two textviews by hidding the first one and showing the second one
textView1.setVisibility(View.GONE);
textView2.setVisibility(View.VISIBLE);
I used these two answers to make it work:
https://stackoverflow.com/a/5488652/1639556
https://stackoverflow.com/a/14195090/1639556
and the code is:
ViewManager parent = (ViewManager) unknown.getParent();
parent.removeView(unknown);
TextView newUnknown = (TextView)getLayoutInflater().inflate(R.layout.tvtemplate, null);
newUnknown.setId(unknown.getId());
parent.addView(newUnknown, unknown.getLayoutParams());
unknown = newUnknown;
You can try using setTextAppearance() on the textview. The link is: setTextAppearance
Your style will need TextAppearance.SomeThing.SomeOtherThing as the parent.
Use R.style.YourStyleName as the integer argument.

Set custom font to Dialog Preferences

I created custom dialog to get input from users extending DialogPreferences class for setting. i need to change font used in dialog and external font using typeface. i set the font to massage using following code. but i couldn't set it for title because i couldn't find the title view also buttons( id of title and buttons).
Text View message = (Text View)view.findViewById(android.R.id.message);
message.setTypeface(font);
how can i do this?
thank you.

How to justify the description in single textview

In my application, I have an TextView with many lines beside of product, but I need the data with proper appearance.Is it possible to have justified alignment dynamically?
you can align your text dynamically some how as you want...
but, i guess there is no such facility available in android to fully justify text as the text editors does...
Use Html Formatting in your textView like
yourTextView.setText(Html.fromHtml("<h1>Product Name</h1><br><p>Content</p>"));
Yes you can get the instance of TextView on activity startup
TextView t = (TextView)FindViewById(R.id.TextView1)
t.setTextAppearance(context,parameter)

Bold Style not applied to textview android

I'm using action bar with custom view for title to be able to add Title and Subtitle
I need to set Title Style to Bold, When I make it in the XML layout it works fine, but I need to set it from code using
textView.setTypeface(null, Typeface.BOLD);
but it does not work, can anyone please help
Ideally it should work. This may sound mundane but can you check if it gets reset somewhere after you set it to bold the first time in your Java file.
You can use this code to display HTML codes in textviews
textView.setText(Html.fromHtml("<b>BOLD WORDS HERE</b>"));

How to give the hint of edittextbox of dialog which is created by code in android

I am creating a dialog box where there is a edit box I want to set the hint of editbox how can I do it.
please help me
thank you
Every EditText is also TextView and the TextView defines a method setHint():
final void setHint(int resid)
Doesn't this work?
EDIT Btw by edit box you mean EditText right?
I am not sure whether this works but might help you,
You could have initialized your Dialog with something like this,
Dialog dialog = null;
And now to Initialize your EditText you should use something like this,
edittext = (EditText) dialog. findViewById(R.id.editbox);
Now use the below method. It should do the trick,
edittext.setHint("Hint");
The same you can provide in the XML file also by adding :
android:hint="Text For Hint"
tag.
For dynamically adding it (in your code and not in XML), Boris & Androi have aldready mentioned it, so wont repeat it.
If you wont be changing once set, then I guess adding in XML is preferred rather than in code.

Categories

Resources