我正在开发一个应用程序,有时它会崩溃,但我的代码没有任何原因。我在 logcat 中唯一的东西是:
2019-10-07 09:55:34.677 15014-15014/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2019-10-07 09:55:34.678 15014-15014/? A/DEBUG: Build fingerprint: 'HUAWEI/POT-LX1/HWPOT-H:9/HUAWEIPOT-L21/264C432:user/release-keys'
2019-10-07 09:55:34.678 15014-15014/? A/DEBUG: Revision: '0'
2019-10-07 09:55:34.678 15014-15014/? A/DEBUG: ABI: 'arm64'
2019-10-07 09:55:34.680 15014-15014/? A/DEBUG: Happend: 'Mon Oct 7 09:55:34 2019
'
2019-10-07 09:55:34.680 15014-15014/? A/DEBUG: SYSVMTYPE: Art
APPVMTYPE: Art
2019-10-07 09:55:34.680 15014-15014/? A/DEBUG: pid: 14772, tid: 15007, name: pool-10-thread- >>> com.example.myapp <<<
2019-10-07 09:55:34.680 15014-15014/? A/DEBUG: signal 11 …
Run Code Online (Sandbox Code Playgroud) 由于右下角的曲线,我想将脚手架主体延伸到 AppBar 后面:
我试过Modifier.offset(y = (-25).dp)
。它工作正常,但 BG 图像不再填充底部导航栏后面的区域:
Scaffold( topBar = { ... }, )
{ padding ->
Box(
Modifier.padding(padding),
contentAlignment = Alignment.TopCenter
) {
Box(
modifier = Modifier
.fillMaxSize()
.offset(y = (-25).dp), // BG image behind AppBar
) {
Image(
modifier = Modifier.fillMaxSize(),
painter = painterResource(R.drawable.bg),
contentDescription = null,
contentScale = ContentScale.FillBounds
)
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能两者兼得?
我有一些内容和一个文本字段,以及屏幕底部的一个按钮。当我点击文本字段时,键盘覆盖了我的按钮,但显然我希望按钮位于键盘上方。我怎样才能做到这一点?
我已经在 setContent() 之前将此行添加到我的 MainActivity 中:
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Run Code Online (Sandbox Code Playgroud)
我的脚手架:
Scaffold { padding ->
Box(
modifier = Modifier
.padding(20.dp)
.padding(top = 40.dp)
.fillMaxSize()
) {
Column {
Text("My content")
Text("My content")
Text("My content")
TextField(
value = text,
onValueChange = { text = it },
)
}
Box(
modifier = Modifier.align(Alignment.BottomCenter)
) {
Button(content = { Text("BTN") }, onClick = {})
}
}
}
Run Code Online (Sandbox Code Playgroud) 如何获取状态栏高度?伴奏插图现已弃用,WindowInsets.systemBars.asPaddingValues()
每次都给我 0...并且Modifier.statusBarsPadding()
在我的布局中不执行任何操作。有什么办法可以达到这个高度吗?
我想在相机预览上方创建一个半透明图层,如下所示:
我在我的应用程序中完成了相机预览,我想要的只是在预览上有一个半透明的图层,带有剪裁的卡片形状,如图所示(带有圆角)。
所以:全屏相机预览,上面有一个全屏半透明覆盖层,其中有一个卡片状的孔被切掉
我怎样才能做到这一点?
我正在使用这个枚举:
public enum FruitType{
APPLE("1", "Apple"),
ORANGE("2", "Orange"),
BANANA("3", "Banana"),
UNKNOWN("0", "UNKNOWN");
private static final Map<String, FruitType> lookup
= new HashMap<String, FruitType>();
static {
for ( FruitType s : EnumSet.allOf(FruitType.class) )
lookup.put(s.getCode(), s);
}
public static FruitType getById(String id) {
for(FruitType e : values()) {
if(e.Code.equals(id)) return e;
}
return UNKNOWN;
}
private String Code;
private String Text;
FruitType( String Code, String Text ) {
this.Code = Code;
this.Text = Text;
}
public final String getCode() {
return Code;
} …
Run Code Online (Sandbox Code Playgroud) 我在 Java 之后开始使用 Kotlin。
我想写一个函数来返回 Single<List<LocationData>>
override fun getDestinations(): Single<List<LocationData>> {
//return ???
}
Run Code Online (Sandbox Code Playgroud)
我的LocationData
班级:
@Parcelize
data class LocationData(val latitude: Double, val longitude: Double) : Parcelable
Run Code Online (Sandbox Code Playgroud)
如何在 Kotlin 中创建List
静态LocationData
对象?
在 Java 中,我会这样做:
override fun getDestinations(): Single<List<LocationData>> {
//return ???
}
Run Code Online (Sandbox Code Playgroud) android ×3
appbar ×1
dereference ×1
enums ×1
java ×1
keyboard ×1
kotlin ×1
material-components-android ×1
offset ×1
statusbar ×1