我cart_layout喜欢这样的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9"
android:id="@+id/cart_listview"
android:layout_gravity="center_horizontal"
android:background="@color/whiteBg"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="bottom"
android:padding="5dp"
android:gravity="bottom"
android:background="@color/whiteBg">
<!-- this layout contains a button and a textview which I don't think is the problem -->
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
以及它的java代码Cart.java:
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cart_layout);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
dbhandler = new DatabaseHandler(this);
product_all = dbhandler.getProduct();
total = (TextView)findViewById(R.id.cart_total_textview);
listview = (ListView)findViewById(R.id.cart_listview);
cart_adapter = new Custom_Cart_Adapter(this,product_all);
listview.setAdapter(cart_adapter);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { …Run Code Online (Sandbox Code Playgroud) 我正在制作一个全屏照片查看器,其中包含一个寻呼机(已使用HorizontalPager)和每个页面,用户可以放大/缩小和平移图像,但仍然可以滑动页面。
我的想法是,当图像未放大(比例因子= 1)时,会发生滑动页面,如果放大(比例因子> 1),则拖动/滑动将平移图像。
HorizontalPager这是包含我的自定义可缩放图像的代码:
@ExperimentalPagerApi
@Composable
fun ViewPagerSlider(pagerState: PagerState, urls: List<String>) {
var scale = remember {
mutableStateOf(1f)
}
var transX = remember {
mutableStateOf(0f)
}
var transY = remember {
mutableStateOf(0f)
}
HorizontalPager(
count = urls.size,
state = pagerState,
modifier = Modifier
.padding(0.dp, 40.dp, 0.dp, 40.dp),
) { page ->
Image(
painter = rememberImagePainter(
data = urls[page],
emptyPlaceholder = R.drawable.img_default_post,
),
contentScale = ContentScale.FillHeight,
contentDescription = null,
modifier = Modifier
.fillMaxSize()
.graphicsLayer(
translationX = transX.value, …Run Code Online (Sandbox Code Playgroud) 所以我有一个Question像下面这样的课程:
@JsonSerializable()
class Question {
String id;
String content;
Question({this.id, this.content});
factory Question.fromJson(Map<String, dynamic> json) =>
_$QuestionFromJson(json);
Map<String, dynamic> toJson() => _$QuestionToJson(this);
}
Run Code Online (Sandbox Code Playgroud)
请记住,那些_$QuestionFromJson和 _$QuestionToJson来自这个库https://pub.dev/packages/json_serializable
假设我有很多类似的类,它们有一个 fromJson 工厂和一个 toJson 方法。我想创建一个包含这两种方法的基类。基本模型对于 toJson 来说很容易,如下所示:
abstract class BaseModel {
Map<String, dynamic> toJson();
}
Run Code Online (Sandbox Code Playgroud)
但是工厂方法呢,我不知道如何声明它们然后简单地像这样覆盖它:
@override
factory Question.fromJson(Map<String, dynamic> json) =>
_$QuestionFromJson(json);
Run Code Online (Sandbox Code Playgroud)
编辑:
我使用它的想法是因为我想创建一个转换器实用程序,我只需要传递像Converter.listFromJson<MyClass>(jsonString). 现在,助手是:
static List<T> listFromJson<T>(jsonString, Function mappingFunction) {
return myJsonMap.map(mappingFunction).cast<T>().toList();
}
Run Code Online (Sandbox Code Playgroud)
所以我每次使用这个辅助方法时都必须通过传递 map 函数来映射每个项目:
Converter.listFromJson<Question>(
jsonMap, (item) => Question.fromJson(item));
Run Code Online (Sandbox Code Playgroud)
还有一些类需要像这样转换为列表。我想重用没有(item) => Question.fromJson(item) …
我正在尝试按照本教程进行操作
但我需要更多关于下拉列表的自定义用户界面。我需要将弹出背景设置为圆形。但是当我添加.clip(RoundedCornerShape(20))到 s 修饰符中时DropdownMenu,它仍然具有白色背景

下面是我的测试可组合代码:
@ExperimentalFoundationApi
@ExperimentalCoilApi
@Composable
fun TestScreen(
navigator: AppNavigator,
) {
var expanded by remember { mutableStateOf(false) }
val items = listOf("A", "B", "C", "D", "E", "F")
val disabledValue = "B"
var selectedIndex by remember { mutableStateOf(0) }
Box(
modifier = Modifier
.fillMaxSize()
.background(Color.Cyan)
.padding(top = 70.dp)
.wrapContentSize(Alignment.TopStart)
) {
Text(
items[selectedIndex],
modifier = Modifier
.fillMaxWidth()
.clickable(onClick = { expanded = true })
.background(
Color.Gray
)
)
DropdownMenu(
expanded = expanded,
onDismissRequest …Run Code Online (Sandbox Code Playgroud) android drop-down-menu android-jetpack-compose android-compose-dropdownmenu
我从接到流PhotoResult的photoChooserTask_Completed(object sender, PhotoResult e)事件处理程序.
它e.ChosenPhoto本身就是一个Stream,所以我将它分配给它Stream stream.我使用以下方法将其转换为byte []数组:
public static byte[] ReadImageFile2(Stream mystream)
{
// The mystream.length is still full here.
byte[] imageData = null;
using (BinaryReader br = new BinaryReader(mystream))
{
imageData = br.ReadBytes(Convert.ToInt32(mystream.Length));
}
// But imageData.length is 0
return imageData;
}
Run Code Online (Sandbox Code Playgroud)
我不知道BinaryReader有什么问题,只返回imageData0长度.试图将类型转换为br.ReadBytes((int)mystream.Length)但仍然无效.
还尝试了从流中创建字节数组但仍然无法正常工作的所有答案.也许我e.ChosenPhoto不能用作普通的Stream.
谢谢.
起初,我的应用程序使用<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">样式。但是我将其更改为 Material Components <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">(为了使用标签的材质徽章计数)。所以改变后的样式是这样的:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/green</item>
<item name="colorPrimaryDark">@color/green</item>
<item name="colorAccent">@color/green</item>
</style>
Run Code Online (Sandbox Code Playgroud)
更改样式后,溢出菜单背景现在为白色。(之前是绿底白字Theme.AppCompat.Light.DarkActionBar)。但是现在背景是白色的,文字也是白色的。
这是工具栏的xml:
<androidx.appcompat.widget.Toolbar
android:id="@+id/ev_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/green"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ToolbarTheme">
</androidx.appcompat.widget.Toolbar>
Run Code Online (Sandbox Code Playgroud)
和工具栏的主题样式:
<style name="ToolbarTheme" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:textColorPrimary">@color/white</item>
<item name="android:colorBackground">@color/green</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我尝试<item name="popupMenuStyle">@style/CustomPopup</item>在AppThemewith 中设置
<style name="CustomPopup" parent="@style/Widget.MaterialComponents.PopupMenu">
<item name="android:popupBackground">@color/green</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但仍然没有运气。
我用来测试的设备使用的是 Android 8.0,compileSdkVersion并且targetSdkVersion是 28。
感谢您的时间。
xml android android-theme material-components material-components-android
我已经有两个星期了这个问题。我使用Wix的导航在应用程序中导航。我按照本教程实施了Deeplink / Universal链接。
我有一个称为的基类BaseScreen,其中像教程中一样保留所有的Deeplink处理程序。这BaseScreen会看起来像这样:
componentDidMount(){
// this handles the case where the app is closed and is launched via Universal Linking.
Linking.getInitialURL()
.then((url) => {
if (url) {
// Alert.alert('GET INIT URL','initial url ' + url)
this.resetStackToProperRoute(url)
}
})
.catch((e) => {})
// This listener handles the case where the app is woken up from the Universal or Deep Linking
Linking.addEventListener('url', this.appWokeUp);
}
componentWillUnmount(){
// Remove the listener
Linking.removeEventListener('url', this.appWokeUp);
}
appWokeUp …Run Code Online (Sandbox Code Playgroud)