0% found this document useful (0 votes)
2 views

Android Notes

The document contains the code for an Android application named 'Silent Mode Toggle', which includes the build configuration in build.gradle, the AndroidManifest.xml for application settings, and layout files such as activity_main.xml and menu_main.xml. The MainActivity.java file defines the main activity with a simple user interface displaying a greeting message and a settings menu option. The app targets SDK version 21 and supports devices with a minimum SDK version of 9.

Uploaded by

Rajkumar Gahlot
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Android Notes

The document contains the code for an Android application named 'Silent Mode Toggle', which includes the build configuration in build.gradle, the AndroidManifest.xml for application settings, and layout files such as activity_main.xml and menu_main.xml. The MainActivity.java file defines the main activity with a simple user interface displaying a greeting message and a settings menu option. The app targets SDK version 21 and supports devices with a minimum SDK version of 9.

Uploaded by

Rajkumar Gahlot
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

build.

gradle (app->)
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
applicationId "com.example.rajkumar.silentmodetoggle"
minSdkVersion 9
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.+'
}
AndroidManifest.xml (app->src->main->res->)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rajkumar.silentmodetoggle" >

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
strings.xml (app->src->main->res->values)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Silent Mode Toggle</string>
<string name="hello_world">Hello Rajkumar!</string>
<string name="action_settings">Settings</string>
</resources>
activity_main.xml (app->src->main->res->layout)
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
menu_main.xml (app->src->main->res->menu)
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
<item android:id="@+id/action_settings" android:title="@string/action_settings"
android:orderInCategory="100" app:showAsAction="never" />
</menu>
MainActivity.java (app->src->main->java)
package com.example.rajkumar.silentmodetoggle;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
@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.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

You might also like