build.
gradle (app->)
apply plugin: '[Link]'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "[Link]"
minSdkVersion 9
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('[Link]'), '[Link]'
}
}}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile '[Link]:appcompat-v7:21.+'
}
[Link] (app->src->main->res->)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="[Link]
package="[Link]" >
<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="[Link]" />
<category android:name="[Link]" />
</intent-filter>
</activity>
</application>
</manifest>
[Link] (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="[Link]
xmlns:tools="[Link] 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="[Link]
xmlns:app="[Link]
xmlns:tools="[Link] tools:context=".MainActivity">
<item android:id="@+id/action_settings" android:title="@string/action_settings"
android:orderInCategory="100" app:showAsAction="never" />
</menu>
[Link] (app->src->main->java)
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate([Link].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 [Link].
int id = [Link]();
//noinspection SimplifiableIfStatement
if (id == [Link].action_settings) {
return true;
}
return [Link](item);
}
}