Archive for 'Java File'

Android, Hide ScrollBar in ScrollView

By default android comes with a scroll bar for scrolling across up and down , but in some specific application we may need to hide the scroll bar and still we should be able to scroll down. So far that kind of application here is the trick to hide the seek bar.

 

Java File

public class HideScrollBarExample extends Activity {

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);

 

ScrollView sView = (ScrollView)findViewById(R.id.ScrollView01);
// Hide the Scollbar
sView.setVerticalScrollBarEnabled(false);
sView.setHorizontalScrollBarEnabled(false);
}
}

Using custom fonts in android

You can use custom fonts in android. For this you have to copy the font file (.ttf ) to the assets folder. Assume your font name is “font1.TTF”. The .ttf will work with all android versions.

Then you have to add a TextView in the main.xml or copy the following text and paste it in your main.xml:

<TextView
android:id="@+id/CustomFontTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="What this font looks like">
</TextView>

Then, copy following code and paste it in the .java file just below the setContentView(R.layout.main) :

Typeface tf = Typeface.createFromAsset(getAssets(), "font1.TTF");
TextView tv = (TextView) findViewById(R.id.CustomFontTV);
tv.setTypeface(tf);

 

That’s it

 

VideoView in Android

main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout android:id="@+id/LinearLayout01"
	android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
	android:paddingLeft="2px" android:paddingRight="2px"
	android:paddingTop="2px" android:paddingBottom="2px"
	android:layout_width="fill_parent" android:orientation="vertical">

	<VideoView android:layout_height="fill_parent"
		android:layout_width="fill_parent" android:id="@+id/VideoView"></VideoView>

</LinearLayout>

Java File

public class VideoPlayerExample extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.main);

		VideoView videoView = (VideoView) findViewById(R.id.VideoView);
		MediaController mediaController = new MediaController(this);
		mediaController.setAnchorView(videoView);
// Set video link (mp4 format )
		Uri video = Uri.parse("mp4 video link");
		videoView.setMediaController(mediaController);
		videoView.setVideoURI(video);
		videoView.start();

	}
}
We Can Build Your App for You. Lets Get Started !