用Compose写抽屉其实很简单,在认识脚手架Scaffold就有提到过,只需在Scaffold给drawerContent赋值即可:
Scaffold(
...
drawerContent = { // 抽屉内容
compose_drawerContent()
}
...
)
然后要打开抽屉的时候调用:
coroutineScope.launch { scaffoldState.drawerState.open() }
就能打开抽屉了。
下面写了个简单的例子:
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import kotlinx.coroutines.launch
import android.os.Bundle
import androidx.activity.ComponentActivity
impo