我尝试在按下按钮时显示 AlertDialog。对于 AlertDialog 我有一个可组合函数 - showDialog。很明显这个函数调用了一个对话框。我有另一个可组合函数,它显示一些带有文本和按钮的窗口。单击按钮时,我想调用一个存储 AlertDialog 的函数。
警报对话框主体:
fun monthDialog() {
val openDialog = remember { mutableStateOf(true) }
if (openDialog.value) {
AlertDialog(
onDismissRequest = {
openDialog.value = false
},
title = {
Text(text = "Title")
},
text = {
Text(
"This area typically contains the supportive text " +
"which presents the details regarding the Dialog's purpose."
)
},
buttons = {
Row(
modifier = Modifier.padding(all = 8.dp),
horizontalArrangement = Arrangement.Center
) {
Button(
modifier = Modifier.fillMaxWidth(),
onClick = …Run Code Online (Sandbox Code Playgroud) 我正在寻找一个返回特定于平台的换行符字符串的函数。我知道System.lineSeparator(),它仅在Kotlin/JVM中可用,但需要一个多平台的等效版本。
我也知道expect/actual方法,但我正在寻找一种更短的方法。(也许是标准库中的函数?)
我用这种方式制作一个导航抽屉并在我的活动中展示它.然后我添加了一个Toolbar到我的基础布局.在这些步骤之后,我尝试这种方式在我的活动上显示三个点.(我在我的基本布局及其类中进行了所有更改).
然后我看到我的活动没有变化.我想我应该用另一种方法在基本活动中添加三个点.我该怎么办?
app_base_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:local="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layoutDirection="rtl"
tools:openDrawer="right">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:minHeight="?attr/actionBarSize"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light"
local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="@android:color/white"
android:textSize="20sp"/>
</android.support.v7.widget.Toolbar>
<FrameLayout
android:id="@+id/view_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"/>
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="@dimen/nav_header_width"
android:layout_height="match_parent"
android:layout_gravity="right"
app:headerLayout="@layout/drawer_header"
app:menu="@menu/drawer"/>
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
AppBaseActivity.java大多是这样的(只有很小的变化).
android android-menu android-activity navigation-drawer android-toolbar