-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathTabActivity.kt
110 lines (95 loc) · 4.26 KB
/
TabActivity.kt
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package com.example.myapplication
import android.app.Activity
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import com.example.myapplication.ui.theme.MyApplicationTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MyApplicationTheme {
ContentListingDemo()
}
}
}
@OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class)
@Preview(
showBackground = true, device = "id:pixel_7_pro", showSystemUi = true, name = "First View"
)
@Composable
private fun ContentListingDemo() {
val act = LocalContext.current as Activity
var state by remember { mutableStateOf(0) }
val titlesAndIcons = listOf(
"Home" to ImageVector.vectorResource(id = R.drawable.baseline_home_24),
"Favorite" to ImageVector.vectorResource(id = R.drawable.baseline_favorite_24),
"Profile" to ImageVector.vectorResource(id = R.drawable.baseline_account_circle_24)
)
Scaffold(
topBar = {
Column {
TopAppBar(
title = {
Text("Tabs Demo", style = MaterialTheme.typography.titleMedium)
},
navigationIcon = {
IconButton(onClick = {
act.finish()
}) {
Icon(imageVector = Icons.Filled.ArrowBack, contentDescription = "Back")
}
},
actions = {
IconButton(onClick = { /* doSomething */ }) {
Icon(imageVector = Icons.Filled.MoreVert, contentDescription = "")
}
},
colors = TopAppBarDefaults.smallTopAppBarColors(
containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(3.dp)
),
)
TabRow(
selectedTabIndex = state,
containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(3.dp)
) {
titlesAndIcons.forEachIndexed { index, (title, icon) ->
Tab(
selected = state == index,
onClick = { state = index },
text = { Text(text = title, maxLines = 2, overflow = TextOverflow.Ellipsis) },
icon = { Icon(icon, contentDescription = null) }
)
}
}
}
},
content = { innPadding ->
//here ur content
// also if you wants to add below listing plz check this link
// https://github.com/Dinesh2510/Jetpack-Compose-UI-Components-Material-3/tree/main/Basic%20Lists
IncludeContent.ContentGridCard(innPadding)
}
)
}
}