Blog purpose for android basic example for android app developer. any query please my contact

Tuesday 20 August 2024

How to Change an Activity Icon in android

  How to Change an Activity Icon in android



Today Learn  How to Change an Activity Icon in android follow this Tutorial.


1.MainActivity.java:


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);

 

    }

 

}



2.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>



3.AndoridManifest.xml:


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

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    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.tutorial"

            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>


No comments:

Post a Comment