Android Program to Change an Activity Icon

Here is source code of the Program to Change an Activity’s Icon in Android using Java. 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.changeicon;
 
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

advertisement
advertisement
<?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.icon_change.taxi"
            android:icon="@drawable/pic"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="com.example.icon_change.taxi" />
 
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
 
    </application>
 
</manifest>

iconchange

Sanfoundry Global Education & Learning Series – 100+ Java Android Tutorials.

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
If you wish to look at all Tutorials, go to Java Android Tutorials.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.