-
Notifications
You must be signed in to change notification settings - Fork 0
/
Android Toolbar (ActionBar) - Tutorial
61 lines (40 loc) · 1.63 KB
/
Android Toolbar (ActionBar) - Tutorial
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//it will make after MainActivity
//make ChildActivity.java
package com.example.codeforactionbar;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class ChildActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_child);
ActionBar actionbar = getSupportActionBar();
actionbar.setTitle("Home");
actionbar.setSubtitle("Back to home page");
actionbar.setHomeButtonEnabled(true);
}
}
//AndroidManifest.xml
//mkae sure Write <activity android:name=".ChildActivity" android:parentActivityName=".MainActivity" />
//set parent Activity & child Activity in android manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.codeforactionbar">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".ChildActivity"
android:parentActivityName=".MainActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>