我想移动所有与主题相关的 xml 代码来编写文件。有一个闪屏 xml 代码,是否可以让它在撰写风格中使用?
<!-- Splash screen theme. -->
<style name="splashScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@drawable/splash_screen</item>
</style>
@Composable
fun splashScreenTheme() {
}
Run Code Online (Sandbox Code Playgroud) 我已经尝试过这两种方法,但都不起作用。
方法一:直接更换Drawer组件。
<Drawer
style={{backgroundImage: url('../../public/images/sideList.jpg')}}>
<div>
<SideList/>
</div>
</Drawer>
Run Code Online (Sandbox Code Playgroud)
方法二:为嵌套div添加background-image属性。
<Drawer>
<BackgroundImageDiv>
<SideList/>
</BackgroundImageDiv>
</Drawer>
Run Code Online (Sandbox Code Playgroud) 我有一个 sharedPreference 对象,我想通过项目将它作为依赖注入组件。
// sharedPreference object
private const val PREF_TAG = "tag"
object MyPreference {
fun getStoredTag(context: Context): String {
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
return prefs.getString(PREF_TAG, "")!!
}
fun setStoredTag(context: Context, query: String) {
PreferenceManager.getDefaultSharedPreferences(context)
.edit()
.putString(PREF_TAG, query)
.apply()
}
}
// How to correctly inject the sharedPreference?
// create a module?
@Module
@InstallIn(SingletonComponent::class)
object PreferenceModule {
@Provides
@Singleton
fun provideSharedPreference(): SharedPreferences {
return MyPreference()
}
}
// or directly inject in viewModel
class LoginViewModel @ViewModelInject constructor(
application: Application,
myPreference: …Run Code Online (Sandbox Code Playgroud) 我尝试从 hms 服务器请求 oauth 令牌,但它总是返回missing required parameter: client_id给我。
url: https://oauth-login.cloud.huawei.com/oauth2/v3/token?grant_type=client_credentials&client_id=XXX&client_secret=XXX
header: Content-Type application/x-www-form-urlencoded
response:
{
"sub_error": 20001,
"error_description": "missing required parameter: client_id",
"error": 1102
}
Run Code Online (Sandbox Code Playgroud) 我想将SpaceBetween属性设置为行对齐,但似乎没有选项可以满足我的需要。
Row(horizontalArrangement = Alignment.SpaceBetween)
Run Code Online (Sandbox Code Playgroud) 我想在observeAsState 上通过委托语法使用状态,但它报告一个错误,显示数据类中没有getValue 方法。
@Composable
fun ComposeScreen(
...
) {
val item: Item by viewModel.item.observeAsState(Item) // there is an error in `(Item)`, it seems not delegate directly using the model of data class.
}
// viewModel
val item = itemRepository.item // item is a LiveData
// model
data class Item(
...
)
Run Code Online (Sandbox Code Playgroud)
更新
我发现解决方案参考了其他人的演示项目,但我仍然不明白为什么要这样做。
import androidx.compose.runtime.getValue
val item: Item? by viewModel.item.observeAsState()
Run Code Online (Sandbox Code Playgroud) Android 中有很多图像查看器库(如stfalcon-studio/StfalconImageViewer)。但目前我找不到一个用于 compose 的,是否可以通过 compose 本机 api 来实现这一目标?只是想在单击图像后在另一个视图中放大和缩小。
用于kubeadm创建集群,我有一个主节点和工作节点。
现在我想在工作节点共享一个,它将与podpersistentVolume绑定。Postgres
期望代码将persistentVolume在工作节点的路径中创建/postgres,但似乎hostPath在集群中不起作用,我应该如何将此属性分配给特定节点?
kind: PersistentVolume
apiVersion: v1
metadata:
name: pv-postgres
labels:
type: local
spec:
capacity:
storage: 2Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/postgres"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: pvc-postgres
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
spec:
selector:
matchLabels:
app: postgres
replicas: 1
strategy: {}
template:
metadata:
labels:
app: postgres
spec:
dnsPolicy: ClusterFirstWithHostNet
hostNetwork: true
volumes:
- name: …Run Code Online (Sandbox Code Playgroud) 我想使用材质图标作为参数将其传递给文本字段。
@Composable
fun NormalTextField(
icon: () -> Unit, // how to pass material icon to textField
label: String
) {
val (text, setText) = mutableStateOf("")
TextField(
leadingIcon = icon,
value = text,
onValueChange = setText,
label = label
)
}
Run Code Online (Sandbox Code Playgroud) 我想出于调试原因打印一些日志,似乎 print 和 Timber 都不适用于 compose,有什么替代选择?
android android-log android-jetpack-compose android-studio-4.2
android ×7
android-log ×1
dagger-hilt ×1
kotlin ×1
kubernetes ×1
material-ui ×1
oauth-2.0 ×1
reactjs ×1