Monthly Archives: October 2013

Ruppe symbol showing in Android

package com.raja.customtoast;

import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;

public class Ruppe extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Typeface typeface = Typeface.createFromAsset(getAssets(), “Rupee.ttf”);
TextView textview = (TextView) findViewById(R.id.textView1);
textview.setTypeface(typeface);
textview.setText(“`”);
}
}

2) activity_main.xml:

<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android&#8221;
    android:layout_width=“match_parent”
    android:layout_height=“match_parent”
    android:background=“#5F04B4”
    android:orientation=“vertical” >
    <TextView
        android:id=“@+id/textView1”
        android:layout_width=“match_parent”
        android:layout_height=“wrap_content”
        android:layout_marginTop=“10dp”
        android:gravity=“center”
        android:text=“Rupee”
        android:textColor=“#FFFFFF”
        android:textSize=“40dp”
        android:textStyle=“bold” />
</LinearLayout>
Paste in asserts
Advertisements

Android Video Streaming (Video View)

Video 

1.Test.java

package com.sample.test;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class Test extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);

/*Intent move=new Intent(Intent.ACTION_VIEW);
move.setDataAndType(Uri.parse(“android.resource://”+getPackageName()+”/”+R.raw.video), “video/*”);
startActivity(move);*/

VideoView videoView =(VideoView)findViewById(R.id.videoView);
MediaController mediaController= new MediaController(this);
mediaController.setAnchorView(videoView);
Uri uri=Uri.parse(“android.resource://”+getPackageName()+”/”+R.raw.video);
videoView.setMediaController(mediaController);
videoView.setVideoURI(uri);
videoView.requestFocus();

videoView.start();
}

}

 

2.activity_test.xml

<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
xmlns:tools=”http://schemas.android.com/tools&#8221;
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical” >

<TextView
android:id=”@+id/textView1″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”@string/hello_world” />

<VideoView
android:id=”@+id/videoView”
android:layout_width=”match_parent”
android:layout_height=”match_parent” />

</LinearLayout>

 

3.AndroidManifest.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
package=”com.sample.test”
android:versionCode=”1″
android:versionName=”1.0″ >

<uses-sdk
android:minSdkVersion=”8″
android:targetSdkVersion=”17″ />

<application
android:allowBackup=”true”
android:icon=”@drawable/ic_launcher”
android:label=”@string/app_name”
android:theme=”@style/AppTheme” >
<activity
android:name=”com.sample.test.Test”
android:label=”@string/app_name” >
<intent-filter>
<action android:name=”android.intent.action.MAIN” />

<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
</application>

</manifest>

Underling Text View in Android

There are three ways of underling the text in Text View.

  1. SpannableString

  2. setPaintFlags(); of TextView

  3. Html.fromHtml();

Let me explain you all approaches :

1st Approach

For underling the text in TextView you have to use SpannableString

String udata="Underlined Text";
SpannableString content = new SpannableString(udata);
content.setSpan(new UnderlineSpan(), 0, udata.length(), 0);
mTextView.setText(content);

2nd Approach

You can make use of setPaintFlags method of TextView to underline the text of TextView.

For eg.

mTextView.setPaintFlags(mTextView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
mTextView.setText("This text will be underlined");

You can refer constants of Paint class if you want to strike thru the text.

3rd Approach

Make use of Html.fromHtml(htmlString);

String htmlString="<u>This text will be underlined</u>";
mTextView.setText(Html.fromHtml(htmlString));

Multi Colors for Single Text view in Android

String your1stString=”Welcome”;
String your2ndString=”RAJA”;
String data=”<font COLOR=\”RED\”><b>” + your1stString + “</b></font> TO <font COLOR=#ff0000><b>” + your2ndString + “</b></font>”;

textviewobj.setText(Html.fromHtml(data));

%d bloggers like this: