我一直在尝试 Jetpack compose,我注意到,尽管Text切换到深色模式时文本颜色会正确更新,但TextField或 的文本颜色OutlinedTextField仍然顽固地保持黑色。不过,标签和提示的颜色正确。
确定字段的默认文本样式是MaterialTheme.typography.body1我已更新我的应用程序主题以包含此解决方法:
val typography = if (darkTheme) {
//TODO: Hack to show text field text in dark mode
MaterialTheme.typography.copy(body1 = MaterialTheme.typography.body1.copy(color = Color.White))
} else {
MaterialTheme.typography
}
MaterialTheme(colors = colors, content = content, typography = typography)
Run Code Online (Sandbox Code Playgroud)
但如果这是解决方案,我就必须对每种排版风格都这样做,而且感觉应该是自动的。那么我是否做错了什么,或者这是在正式发布之前将得到解决的问题之一?
这是我的实际可组合项之一(包含在我的主题中):
@Composable
fun UsernameField(
value: String,
isError: Boolean,
onValueChange: (String) -> Unit,
) {
Column {
OutlinedTextField(
value = value,
onValueChange = onValueChange,
modifier = Modifier.fillMaxWidth(),
label = { Text("Username") }, …Run Code Online (Sandbox Code Playgroud) android android-jetpack-compose android-darkmode android-compose-textfield
我在 Jetpack compose 中创建了一个相当经典的折叠图像布局,其中屏幕顶部有一个图像,该图像视差滚动消失,并且在某个时刻我将工具栏背景从透明更改为primarySurface。这一切都运行得很好。
我现在希望在顶部有一个图像寻呼机,而不是单个图像,但垂直滚动消耗了屏幕顶部的所有触摸。我尝试添加 NestedScrollConnection 但我似乎仍然只在一个轴上获得 preScroll 增量。显然,我什至无法在该区域中添加图标来进行手动寻呼机滚动而不消耗点击。一旦我删除verticalScroll从我的列中删除 ,我就能够获取寻呼机的水平滚动事件。
我正在使用 Compose 1.0.2 和 Accompanist 0.18 寻呼机和插图库。
这是我想要添加寻呼机的现有代码的要点。如何让寻呼机和垂直滚动同时工作?
val scrollState = rememberScrollState()
Box {
val imageHeight =
if (LocalConfiguration.current.orientation == Configuration.ORIENTATION_LANDSCAPE) 180.dp else 300.dp
Box {
// I want to insert a horizontal pager here
HeaderImage(
scrollPosition = scrollState.value,
info = item.heroImages.first(),
imageHeight = imageHeight
)
}
val appBarHeight = with(LocalDensity.current) { 56.dp.toPx() }
val scrollHeight = with(LocalDensity.current) { imageHeight.toPx() - appBarHeight }
Column(
Modifier
.verticalScroll(scrollState)
.padding(top = …Run Code Online (Sandbox Code Playgroud) android-viewpager android-collapsingtoolbarlayout android-jetpack-compose jetpack-compose-accompanist
由于GAE在上周初进入定价模型,我一直在努力超越我的Datastore读写操作配额.我不确定Google是否将一个编写器的所有更新都计为一次写入,或者每个列更新是否都计为单独写入.
如果后者是真的,我可以通过使用一个更新函数来更新参数中的6列来解决这个问题,或者我是否也需要为6次更新付费?
这是我现有的代码,用于同时更新玩家的分数(评分)和其他详细信息.目前,我总是使用客户端的值填充姓名,电子邮件,评级,赢取,播放和成就.一种解决方案可能是仅在客户端更改值时从客户端发送这些解决方案.
Long key = Long.valueOf(updateIdStr);
System.out.println("Key to update: " + key);
PlayerPersistentData ppd =null;
try {
ppd = pm.getObjectById(
PlayerPersistentData.class, key);
// for all of these, make sure we actually got a value via
// the query variables
if (name != null && name.length() > 0) {
ppd.setName(name);
}
if (ratingStr != null && ratingStr.length() > 0) {
ppd.setRating(rating);
}
if (playedStr != null && playedStr.length() > 0) {
ppd.setPlayed(played);
}
if (wonStr != null && wonStr.length() > …Run Code Online (Sandbox Code Playgroud) 我刚刚修改了我们的代码以使用v7-appcompat库中提供的新SupportActionBar但是当在Jellybean手机上运行代码时(可能是Honeycomb和Ice Cream Sandwich存在相同的问题),主页按钮似乎永远不会被激活.
调用getSupportActionBar().setHomeButtonEnabled(true); 似乎没有做它说的但适用于姜饼手机.
如果我用getActionBar()替换它.setHomeButtonEnabled(true)它确实有效.
我用于v11 +的主题如下:
<style name="MyTheme" parent="@style/Theme.AppCompat">
<item name="android:windowActionBar">true</item>
<item name="android:windowNoTitle">false</item>
<item name="android:listViewStyle">@style/MyListView</item>
<item name="android:actionBarStyle">@style/MyActionBarStyle</item>
<item name="android:windowSoftInputMode">stateAlwaysHidden</item>
<item name="android:buttonStyle">@style/MyButton</item>
<item name="android:radioButtonStyle">@style/MyRadioButtonStyle</item>
<item name="android:windowContentOverlay">@drawable/ab_solid_dove_grey</item>
<item name="android:windowTitleSize">@dimen/action_bar_height</item>
<item name="android:selectableItemBackground">@drawable/sel_standard_item</item>
<item name="android:windowBackground">@drawable/default_bg</item>
<item name="android:actionMenuTextAppearance">@style/MyActionBarText</item>
<item name="android:actionMenuTextColor">@color/gallery</item>
<item name="android:tabWidgetStyle">@style/MyTabWidget</item>
</style>
Run Code Online (Sandbox Code Playgroud)
并定义了动作栏样式v11 +:
<style name="MyActionBarStyle" parent="android:style/Widget.Holo.ActionBar">
<item name="android:displayOptions">useLogo|showHome|showCustom</item>
<item name="displayOptions">useLogo|showHome|showCustom</item>
<item name="android:actionBarSize">@dimen/action_bar_height</item>
<item name="android:icon">@drawable/ic_launcher</item>
<item name="android:background">@android:color/transparent</item> <!-- Remove blue line from bottom of action bar -->
</style>
Run Code Online (Sandbox Code Playgroud)
任何人都知道为什么在正确支持操作栏的Android版本上没有启用主页按钮.
=== UPDATE ===我刚刚查看了appcompat库的源代码,我注意到ActionBarImplBase中的以下内容对我来说是错误的:
setHomeButtonEnabled(abp.enableHomeButtonByDefault() || homeAsUp);
Run Code Online (Sandbox Code Playgroud)
这意味着只有在Android版本低于ICS或者我启用了向上指示器时才会启用主页按钮? - 我不想要的.
我试图提供一个通用的,DataStore<Preferences>以便可以在多个地方使用相同的首选项文件,但我收到了有用的错误消息:
找不到符号:DaggerMyApplication_HiltComponents_SingletonC.builder()
@Module
@InstallIn(ApplicationComponent::class)
object DataStoreModule {
@Provides
fun provideDataStore(@ApplicationContext context: Context): DataStore<Preferences> = context.createDataStore("settings")
}
Run Code Online (Sandbox Code Playgroud)
但是,我可以执行以下操作并在@Inject构造函数中使用它。
@Singleton
class DataStoreProvider @Inject constructor(@ApplicationContext context: Context) {
val dataStore: DataStore<Preferences> = context.createDataStore("settings")
}
Run Code Online (Sandbox Code Playgroud)
我认为扩展程序createDataStore正在做一些 Hilt 不喜欢的事情,但即使问题无法解决,我也希望能解释一下正在发生的事情。
我在开发者控制台上收到此消息,指出我的应用程序因为以下原因而冻结:
ANR意向广播{act = android.intent.action.SCREEN_OFF flg = 0x40000000}
没有堆栈跟踪,因为这是由前Froyo用户引发的.它甚至没有告诉我应用程序中的哪个活动导致了错误 - 尽管我猜这是我的游戏活动.
这也符合我自己的经验,有时当我的手机电池电量不足时,我的应用程序将冻结并且必须被杀死.
我应该在我的活动中做些什么来处理这个冻结状态?
我现在从市场上得到了一些适当的输出,但我仍然不知道如何处理它.
DALVIK THREADS:
"main" prio=5 tid=1 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x400227b0 self=0xce98
| sysTid=4060 nice=0 sched=0/0 cgrp=default handle=-1345013476
| schedstat=( 72099976000 6131816000 28732 )
at android.media.SoundPool.play(Native Method)
at com.bazsoft.yaniv.SoundManager.playSound(SoundManager.java:88)
at com.bazsoft.yaniv.YanivGameActivity.displayPileCards(YanivGameActivity.java:675)
at com.bazsoft.yaniv.YanivGameActivity.access$22(YanivGameActivity.java:659)
at com.bazsoft.yaniv.YanivGameActivity$1.run(YanivGameActivity.java:628)
at android.app.Activity.runOnUiThread(Activity.java:3713)
at com.bazsoft.yaniv.YanivGameActivity.displayCards(YanivGameActivity.java:615)
at com.bazsoft.yaniv.YanivGameActivity.access$6(YanivGameActivity.java:614)
at com.bazsoft.yaniv.YanivGameActivity$ComputerHandler.handleMessage(YanivGameActivity.java:121)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4701)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:859)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:617)
at dalvik.system.NativeStart.main(Native Method)
"AsyncTask #5" prio=5 tid=19 WAIT
| …Run Code Online (Sandbox Code Playgroud) 我在新的 Jetpack Compose 应用程序中设置了一个包含 2 个目的地的底部栏。我尝试遵循谷歌的示例。
例如,它看起来像这样:
@Composable
fun MyBottomBar(navController: NavHostController) {
val items = listOf(
BottomNavigationScreen.ScreenA,
BottomNavigationScreen.ScreenB
)
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentDestination = navBackStackEntry?.destination
BottomNavigation {
items.forEach { screen ->
BottomNavigationItem(
onClick = {
navController.navigate(screen.route) {
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
},
selected = currentDestination?.hierarchy?.any { it.route == screen.route } == true,
icon = { Icon(imageVector = screen.icon, contentDescription = null) },
label = { Text(stringResource(screen.label)) }
)
} …Run Code Online (Sandbox Code Playgroud) deep-linking android-architecture-navigation android-jetpack-compose
我的主要AsyncTasks之一似乎偶尔会崩溃(进度条冻结并且进程停止)我想知道我的代码中是否有错误.
看起来当我的Galaxy S2开始耗尽电量时可能会发生这种情况 - 这似乎与亮度控制方面的一些错误相吻合.虽然这些是错误的原因还是由错误导致的,但我还是无法确定.此外,由于电池似乎总是低电量,这可能甚至没有关联!
我在AsyncTask中做的任何事情是错的吗?我实际上只是在使用处理程序执行实际计算机之前,使用AsyncTask显示三个进度条中的一个(计算机播放器).
这也是Android市场上从未报道过的.如果它是由InterruptedException引起的,我是否还应该打印堆栈跟踪,以便在我的最终用户发生用户时出现错误?
//Declaration at top level of activity
private ComputerPlayerTask mComputerPlayerTask = new ComputerPlayerTask();
// Execution of the task with a random integer value
mComputerPlayerTask = new ComputerPlayerTask();
mComputerPlayerTask.execute(randomInt);
private class ComputerPlayerTask extends
AsyncTask<Integer, Integer, Boolean> {
private ProgressBar mProgressBar;
@Override
protected Boolean doInBackground(Integer... params) {
int delayTime = params[0];
mProgressBar.setMax(delayTime - 1);
for (int i = 0; i < delayTime; i++) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
Log.e(DEBUG_TAG, "Can't sleep thread"); …Run Code Online (Sandbox Code Playgroud) android ×5
android-architecture-navigation ×1
android-collapsingtoolbarlayout ×1
crash ×1
dagger-hilt ×1
deep-linking ×1
freeze ×1
jetpack-compose-accompanist ×1
kotlin ×1