072 Java Android Program to Set an Activity in Potrait Mode
Posted by Superadmin on February 27 2017 04:28:13

Java Android Program to Set an Activity in Potrait Mode

Here is source code of the Program to Set an Activity in Potrait Mode in Andorid. The program is successfully compiled and run on a Windows system using Eclipse Ide. The program output is also shown below.

 

MainActivity.java

package com.example.d_indicator;
 
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.Toast;
 
public class MainActivity extends Activity implements OnClickListener {
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
 
}

Activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >
 
    <ImageButton
        android:id="@+id/taxi"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/metro"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/metro"
        android:layout_marginTop="33dp"
        android:src="@drawable/taxixx" />
 
    <ImageButton
        android:id="@+id/auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/taxi"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/taxi"
        android:layout_marginTop="31dp"
        android:src="@drawable/autoxx" />
 
    <ImageButton
        android:id="@+id/movies"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/auto"
        android:layout_alignRight="@+id/auto"
        android:layout_below="@+id/auto"
        android:layout_marginTop="36dp"
        android:src="@drawable/moviesxx" />
 
    <ImageButton
        android:id="@+id/metro"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="40dp"
        android:src="@drawable/metroxx" />
 
</RelativeLayout>

AndoridManifest.xml

Here is source code of the Program to Change of an Activity’s Icon in Andorid. The program is successfully compiled and run on a Windows system using Eclipse Ide. The program output is also shown below.

 

MainActivity.java

package com.example.d_indicator;
 
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
 
public class MainActivity extends Activity implements OnCheckedChangeListener {
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        // setting our activity to be full screen
        setContentView(R.layout.activity_main);
 
    }
 
}

Activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:background="@drawable/taxi_back1">
 
    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/taxi_result"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="27dp"
        android:text="Your Total Fare"
        android:textColor="@android:color/black"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="20dp" />
 
    <EditText
        android:id="@+id/taxi__distance"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textView2"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="26dp"
        android:ems="10" />
 
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/taxi__distance"
        android:layout_alignParentLeft="true"
        android:text="Enter Distance"
        android:textColor="@android:color/black"
        android:textAppearance="?android:attr/textAppearanceLarge" />
 
    <EditText
        android:id="@+id/taxi_result"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/taxi_button"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="36dp"
        android:ems="10" >
 
        <requestFocus />
    </EditText>
 
    <Button
        android:id="@+id/taxi_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignRight="@+id/textView2"
        android:layout_marginBottom="36dp"
        android:background="@android:color/darker_gray"
        android:text="CALCULATE"
        android:textAlignment="viewStart"
        android:textColor="@android:color/black"
        android:textSize="15dp" />
 
    <Button
        android:id="@+id/taxi_reset"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/taxi_result"
        android:layout_toRightOf="@+id/taxi_result"
        android:background="@android:color/darker_gray"
        android:text="RESET"
        android:textAlignment="viewStart"
        android:textColor="@android:color/black"
        android:textSize="15dp" />
 
    <ImageButton
        android:id="@+id/taxi_phone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/phone" />
 
    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/taxi_phone"
        android:orientation="horizontal"
        android:paddingBottom="40px"
        android:weightSum="2" >
 
        <RadioGroup
            android:id="@+id/taxi_rg1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical" >
 
            <RadioButton
                android:id="@+id/taxi_day"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="DAY" />
 
            <RadioButton
                android:id="@+id/taxi_night"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="NIGHT" />
        </RadioGroup>
 
        <RadioGroup
            android:id="@+id/taxi_rg2"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical"
            android:paddingLeft="70px" >
 
            <RadioButton
                android:id="@+id/taxi_ac"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="AC" />
 
            <RadioButton
                android:id="@+id/taxi_nonac"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="NON-AC" />
        </RadioGroup>
    </LinearLayout>
 
    <ImageButton
        android:id="@+id/taxi_arrow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/taxi__distance"
        android:src="@drawable/arrow" />
 
</RelativeLayout>

AndoridManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.d_indicator"
    android:versionCode="1"
    android:versionName="1.0" >
 
    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="17" />
 
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
 
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
      <!--to change icon specify the drawable in android:icon as shown -->
            <activity
            android:name="com.example.d_indicator.MainActivity"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
 
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
 
</manifest>