Jetnews is a sample news reading app, built with Jetpack Compose. The goal of the sample is to showcase the current UI capabilities of Compose.
To try out this sample app, use the latest stable version of Android Studio. You can clone this repository or import the project from Android Studio following the steps here.
This sample contains three screens: a list of posts, a detail page for a post, and a page to subscribe to topics of interest. The navigation from the list of posts to the interests screen uses a navigation drawer.
Package com.example.jetnews.ui
JetnewsApp.kt sets up the app's navigation state and the modal drawer used for navigation
on smaller windows.
JetnewsNavDisplay.kt displays the primary content of the app: the list of posts, the
posts themselves, and the interests page. It uses a list-detail scene strategy to adaptively
display more or less content depending on the window size.
Package com.example.jetnews.ui.home
This screen shows how to create different custom Composable functions and combine them in a list that scrolls vertically and horizontally.
See how to:
- Use
Rows andColumns to arrange the contents of the UI - Add a top app bar that elevates as the user scrolls
- Use Material's
TypographyandColorSchemeto style the text - Use tonal elevation to make the
Cards stand out from the background
Package com.example.jetnews.ui.post
This screen dives into the Text API, showing how to use different fonts than the ones defined in
Typography. It also adds a bottom app bar, with custom actions.
Package com.example.jetnews.ui.interests
This screens shows how to use Tabs and switch content depending on the selected tab. It
also includes a custom checkbox button, SelectTopicButton
that uses a Toggleable composable function to provide
the on/off behaviour and semantics, while drawing a custom UI. The UI of the button is partly
drawn with low-level primitives and partly overlaying images. See also how to visualize
on and off, light and dark version in the Android Studio Preview.
Package com.example.jetnews.glance
This package shows how to use Glance and write compose style code for AppWidgets.
See how to:
- Use
Row,Column,LazyColumnto arrange the contents of the UI - Use a repository from your existing app to load data for the widget and perform updates
- Configure
android:updatePeriodMillisto periodically refresh the widget - Use
androidx.glance:glance-material3library to create a custom color scheme withGlanceThemeand use dynamic colors when supported - Tint
Images to match the color scheme - Launch an activity on click using
actionStartActivity
The data in the sample is static, held in the com.example.jetnews.data package.
UI tests can be run on device/emulators or on JVM with Robolectric.
- To run Instrumented tests use the "Instrumented tests" run configuration or run the
./gradlew connectedCheckcommand. - To run tests with Robolectric use the "Robolectric tests" run configuration or run the
./gradlew testDebugcommand.
Copyright 2021 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

