Make Links In TextView Clickable

There will be cases where we may want our text in strings.xml intact without adding HTML tags in order for hyperlinks to be shown as underlined and colored blue. Just like my experience.

I did not want the text in my strings.xml file for this certain variable to have HTML formatted tags within it.

Let us have an example:

<string name="test">This is a hyperlink, so <a href="http://www.google.com">click me</a>.</string>

To make the hyperlink in the TextView to be linkable, simply call this programmatically:

textview.setMovementMethod(LinkMovementMethod.getInstance());

That is all. Do not add the attribute android:autoLink=”web” in your layout XML, or else it won’t work.

Maqruee Scrolling TextView In Android Widget

An Android Widget does not provide any way to get a reference to any control like a TextView. So what if you wanted a horizontal scrolling marquee TextView?

While doing it in an app is pretty easy since you can get hold of a TextView object and even doing it programmatically by giving focus to the TextView object, a widget is different. However, there is a way within the XML to make this happen.

See the XML example.

<TextView android:id="@+id/mytextview" 
	android:text="this is a horizontal scrolling text sample ..." 
	android:singleLine="true" android:ellipsize="marquee"
	android:layout_width="wrap_content"  android:layout_height="wrap_content" 
	android:marqueeRepeatLimit="marquee_forever"
      	android:scrollHorizontally="true" android:focusable="true"
      	android:focusableInTouchMode="true" android:duplicateParentState="true"
>
 	<requestFocus android:focusable="true" android:focusableInTouchMode="true"
 		      android:duplicateParentState="true" 
	/>
</TextView>

This way, whenever your widget gets called, the TextView that will display the marquee text will have focus right away and will be able to show the horizontal animating effect that you so want.

Android: Span Columns In A TableRow

Setting a View like an ImageView or TextView within a TableRow spanning N number of columns can be done within the XML layout file using the android:layout_span attribute in the View object, not the TableRow.

Check out the sample xml code below. Since the second row contains 3 columns with 3 different ImageView objects and the first row contains only one ImageView, the android:layout_span is called to span the first row with 3 columns.

<TableLayout android:id="@+id/tableLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:stretchColumns="*">
    	<TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content">
            <ImageView android:id="@+id/imageView7" android:layout_height="wrap_content" android:src="@drawable/imagelogo" android:layout_width="wrap_content" android:scaleType="centerInside" android:layout_span="3"></ImageView>          
        </TableRow>
    	<TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content">
    		<ImageView android:id="@+id/imageView1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/image1"></ImageView>
    		<ImageView android:id="@+id/imageView2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/image2"></ImageView>
    		<ImageView android:id="@+id/imageView3" android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/image3"></ImageView>        
        </TableRow>
</TableLayout>
Related Posts Plugin for WordPress, Blogger...