Android Program -Touch Activity

ANDROID FOR FRESHERS

Android Program Touch Activity

Java Code(TouchAct )

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;

public class TouchAct extends Activity {
LinearLayout l3;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_touch);
l3=(LinearLayout)findViewById(R.id.l3);
}

@Override
public boolean onTouchEvent(MotionEvent event)
{
super.onTouchEvent(event);
int act = event.getAction();
if (act == MotionEvent.ACTION_DOWN)
{
l3.setBackgroundColor(Color.BLUE);
}
else
{
if (act == MotionEvent.ACTION_UP)
{
l3.setBackgroundColor(Color.WHITE);
}
else
{
if (act == MotionEvent.ACTION_MOVE)
{
l3.setBackgroundColor(Color.RED);
}

}
}
return true;
}

}

Layout XML Code(activity_touch)

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:tools=”http://schemas.android.com/tools”
android:layout_width=”match_parent”
android:orientation=”vertical”
android:layout_height=”match_parent”
android:paddingBottom=”@dimen/activity_vertical_margin”
android:paddingLeft=”@dimen/activity_horizontal_margin”
android:paddingRight=”@dimen/activity_horizontal_margin”
android:id=”@+id/l3″
android:paddingTop=”@dimen/activity_vertical_margin”
tools:context=”com.andro.tech.androidproject.TouchAct”>

<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:textSize=”20sp”
android:layout_marginLeft=”10dp”
android:text=”@string/touchtext”
android:layout_marginBottom=”300dp” />

<Button
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”@string/sourcecode”
android:background=”@color/bgcolor”
android:textStyle=”bold”
android:textColor=”@color/text”
android:onClick=”view1″/>

</LinearLayout>

Output

Android touch activity java snippet code download   Android touch activity java snippet code download

Android Touch activity java snippet code download

Download Touch Activity Source Code

For More Android Programs –Click Here

 

Follow Us – Never Miss Update

Fb/PageTwitterGoogle+InstagramPinterest 

 

Related Search

Android touch activity snippet code download, android touch code download, android touch onclick source code download, android touch on off code download, touch activity on off android code, android screen touch code download, download touch sensation on off code android, touch activity android snippet java code download, Android touch activity java snippet code download

Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

    Comments