我想知道如何添加多个修饰符,例如向 Android jetpack 可组合项添加背景、填充等?
我在 android studio 中创建了一个新的 flutter 项目,然后“打开项目”它的 android 部分,我在 MainActivity.kt 中遇到了一个错误,但是它构建成功。
我的课程路径是:
最后我的依赖项是:
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.70"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Run Code Online (Sandbox Code Playgroud)
如果有人可以帮助我,我将不胜感激。
我有一个对话框,我将其包装在 blocbuilder 中以根据状态类型更新它,但该对话框只是第一次构建,在状态更改后它不会重建。
showDialog(
context: context,
builder: (_) {
BlocBuilder<ExampleCubit, ExampleState>(
bloc: cubit,
builder: (context, state) {
return CustomDialog(
title:"title",
onSave: (File file) {
cubit.uploadImage(file);
},
progress: (state is ExtendedExampleState)? state.progress:0,
onDelete: () {},
onCancel: () {
cubit.cancelUploading();
},
);
},
);
Run Code Online (Sandbox Code Playgroud)
注意:使用 Bloc 模式很重要StateFulBuilder。
我使用包含布局,我需要更改它的可见性:
<include
android:id="@+id/layout_provinces"
layout="@layout/layout_select_provinces"
/>
Run Code Online (Sandbox Code Playgroud)
而 layout_select_provinces 是这样的:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/select_province"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/white"
android:visibility="gone">
<LinearLayout
android:id="@+id/layout_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background_color"
android:orientation="vertical">
<TextView
android:id="@+id/txt_state"
style="@style/FontIranBold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="@dimen/_8sdp"
android:layout_marginRight="@dimen/_4sdp"
android:layout_marginBottom="@dimen/_8sdp"
android:text="@string/txt_select_province"
android:textSize="@dimen/font_size_small" />
<View
android:layout_width="match_parent"
android:layout_height="@dimen/_1sdp"
android:background="@color/gray_special" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_estate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/layout_top"
android:layout_marginTop="@dimen/_8sdp" />
Run Code Online (Sandbox Code Playgroud)
但是当我将 Id 设置为 RelativeLayout 时,我的应用程序崩溃并且我无法更改可见性:
binding.layoutProvinces.selectProvince.setVisibility(View.GONE);
Run Code Online (Sandbox Code Playgroud)
有没有人可以帮助我处理 ViewBinding 设置 ID 过程?