小编ccd*_*ccd的帖子

如何在撰写 theme.kt 文件上创建启动画面主题

我想移动所有与主题相关的 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)

android android-theme android-jetpack-compose

7
推荐指数
1
解决办法
809
查看次数

如何在material-ui抽屉组件中添加背景图片

我已经尝试过这两种方法,但都不起作用。

方法一:直接更换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)

reactjs material-ui

6
推荐指数
1
解决办法
9585
查看次数

在刀柄中包装 sharedPreference 对象的最佳方法

我有一个 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)

android dagger-hilt

6
推荐指数
2
解决办法
2882
查看次数

缺少必需参数:client_id

我尝试从 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)

oauth-2.0 huawei-mobile-services huawei-account

6
推荐指数
1
解决办法
2万
查看次数

Jetpack Compose 的行和列中的对齐和排列如何工作?

我想将SpaceBetween属性设置为行对齐,但似乎没有选项可以满足我的需要。

Row(horizontalArrangement = Alignment.SpaceBetween)
Run Code Online (Sandbox Code Playgroud)

android android-jetpack-compose

5
推荐指数
0
解决办法
2214
查看次数

通过在observeAsState 上委托数据类

我想在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 kotlin android-jetpack-compose

5
推荐指数
1
解决办法
1836
查看次数

如何在 compose 中创建图像查看器

Android 中有很多图像查看器库(如stfalcon-studio/StfalconImageViewer)。但目前我找不到一个用于 compose 的,是否可以通过 compose 本机 api 来实现这一目标?只是想在单击图像后在另一个视图中放大和缩小。

android android-jetpack-compose

5
推荐指数
0
解决办法
1261
查看次数

HostPath 将 persistVolume 分配给集群中的特定工作节点

用于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)

kubernetes persistent-volumes persistent-volume-claims

4
推荐指数
1
解决办法
6308
查看次数

如何将android compose材质图标传递给textField

我想使用材质图标作为参数将其传递给文本字段。

@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)

android google-material-icons android-compose-textfield

4
推荐指数
1
解决办法
8305
查看次数

如何打印撰写日志

我想出于调试原因打印一些日志,似乎 print 和 Timber 都不适用于 compose,有什么替代选择?

android android-log android-jetpack-compose android-studio-4.2

4
推荐指数
1
解决办法
1万
查看次数