Skip to content

Commit 516f36e

Browse files
malandr2copybara-github
authored andcommitted
Update app bar layout to support Android >=15
PiperOrigin-RevId: 822110705
1 parent 4faf9a1 commit 516f36e

File tree

4 files changed

+62
-34
lines changed

4 files changed

+62
-34
lines changed

kotlin/admob/NativeAdvancedExample/app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ dependencies {
3737
implementation 'androidx.appcompat:appcompat:1.2.0'
3838
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
3939
implementation 'com.google.android.gms:play-services-ads:24.7.0'
40+
implementation 'com.google.android.material:material:1.13.0'
4041
implementation 'com.google.android.ump:user-messaging-platform:3.2.0'
4142
}

kotlin/admob/NativeAdvancedExample/app/src/main/java/com/google/android/gms/example/nativeadvancedexample/MainActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class MainActivity : AppCompatActivity() {
5454
super.onCreate(savedInstanceState)
5555
mainActivityBinding = ActivityMainBinding.inflate(layoutInflater)
5656
setContentView(mainActivityBinding.root)
57+
setSupportActionBar(mainActivityBinding.toolBar)
5758

5859
// Log the Mobile Ads SDK version.
5960
Log.d(TAG, "Google Mobile Ads SDK Version: " + MobileAds.getVersion())
Lines changed: 59 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,73 @@
1-
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
1+
<androidx.constraintlayout.widget.ConstraintLayout
2+
xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
24
xmlns:tools="http://schemas.android.com/tools"
3-
android:id="@+id/root_view"
45
android:layout_width="match_parent"
56
android:layout_height="match_parent"
6-
tools:context="com.google.android.gms.example.nativeadvancedexample.MainActivity">
7+
tools:context=".MainActivity">
78

8-
<LinearLayout
9+
<com.google.android.material.appbar.AppBarLayout
10+
android:id="@+id/app_bar_layout"
911
android:layout_width="match_parent"
1012
android:layout_height="wrap_content"
11-
android:orientation="vertical">
13+
android:fitsSystemWindows="true"
14+
android:background="@color/colorPrimaryDark"
15+
app:layout_constraintTop_toTopOf="parent">
1216

13-
<FrameLayout
14-
android:id="@+id/ad_frame"
17+
<com.google.android.material.appbar.MaterialToolbar
18+
android:id="@+id/toolBar"
1519
android:layout_width="match_parent"
16-
android:layout_height="wrap_content"
17-
android:layout_marginTop="16dp" />
20+
android:layout_height="?attr/actionBarSize"
21+
app:titleTextColor="@android:color/white"
22+
app:title="@string/app_name" />
1823

19-
<CheckBox
20-
android:id="@+id/start_muted_checkbox"
21-
android:layout_width="wrap_content"
22-
android:layout_height="wrap_content"
23-
android:checked="true"
24-
android:text="Start video ads muted" />
24+
</com.google.android.material.appbar.AppBarLayout>
2525

26-
<Button
27-
android:id="@+id/refresh_button"
28-
android:layout_width="wrap_content"
29-
android:layout_height="wrap_content"
30-
android:layout_gravity="center_horizontal"
31-
android:layout_marginBottom="16dp"
32-
android:layout_marginTop="16dp"
33-
android:text="Refresh Ad"
34-
android:visibility="gone" />
35-
36-
<TextView
37-
android:text="Video status: "
26+
<ScrollView
27+
android:id="@+id/root_view"
28+
android:layout_width="match_parent"
29+
android:layout_height="0dp"
30+
app:layout_constraintTop_toBottomOf="@id/app_bar_layout"
31+
app:layout_constraintBottom_toBottomOf="parent">
32+
33+
<LinearLayout
3834
android:layout_width="match_parent"
3935
android:layout_height="wrap_content"
40-
android:layout_marginLeft="16dp"
41-
android:layout_marginRight="16dp"
42-
android:id="@+id/video_status_text"
43-
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
36+
android:orientation="vertical">
37+
38+
<FrameLayout
39+
android:id="@+id/ad_frame"
40+
android:layout_width="match_parent"
41+
android:layout_height="wrap_content"
42+
android:layout_marginTop="16dp" />
43+
44+
<CheckBox
45+
android:id="@+id/start_muted_checkbox"
46+
android:layout_width="wrap_content"
47+
android:layout_height="wrap_content"
48+
android:checked="true"
49+
android:text="Start video ads muted" />
50+
51+
<Button
52+
android:id="@+id/refresh_button"
53+
android:layout_width="wrap_content"
54+
android:layout_height="wrap_content"
55+
android:layout_gravity="center_horizontal"
56+
android:layout_marginBottom="16dp"
57+
android:layout_marginTop="16dp"
58+
android:text="Refresh Ad"
59+
android:visibility="gone" />
60+
61+
<TextView
62+
android:id="@+id/video_status_text"
63+
android:layout_width="match_parent"
64+
android:layout_height="wrap_content"
65+
android:layout_marginLeft="16dp"
66+
android:layout_marginRight="16dp"
67+
android:text="Video status: "
68+
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
4469

70+
</LinearLayout>
71+
</ScrollView>
4572

46-
</LinearLayout>
47-
</ScrollView>
73+
</androidx.constraintlayout.widget.ConstraintLayout>

kotlin/admob/NativeAdvancedExample/app/src/main/res/values/styles.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<resources>
22

33
<!-- Base application theme. -->
4-
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
4+
<style name="AppTheme" parent="Theme.Material3.DayNight.NoActionBar">
55
<!-- Customize your theme here. -->
66
<item name="colorPrimary">@color/colorPrimary</item>
77
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>

0 commit comments

Comments
 (0)