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

Comments

vivo V30e launched in India starting at ₹27999: Full Specs & features HMD Launches Nokia 215, 225, & 235 4G Phone: Full Specs and Pricing Apple 2024 iPad Pro: Premier OLED Panels & M4 Chip, Debuting May 7 6 Best PC Games like Fall Guys in 2024 6 Best Gaming Phones to Play Free Fire MAX in India (2024)