小编Tyk*_*kin的帖子

触发 Widget 布局的 Android 10 主题更新

随着 Android 10 的发布,多个小部件(Gmail、Google 新闻、三星电子邮件)现在会在切换深色模式时更新其主题。我正在尝试复制这种行为。我有一个带有 AppWidgetProvider 和 RemoteViewsFactory 的列表视图小部件。但是,当切换深色模式时,ListView 项目会切换到深色主题,而不是布局本身:

深色模式关闭:

深色模式关闭

深色模式开启:

深色模式开启

在我的代码中,我在 AppWidgetProvider 的 OnUpdate() 方法中设置布局:

    override fun onUpdate(
    context: Context,
    appWidgetManager: AppWidgetManager?,
    appWidgetIds: IntArray?
) {

    Log.d(TAG, "Updating Transaction Widget")

    GlobalScope.launch(Dispatchers.IO ) {
        updateTransactionTable(context)
        for (i in appWidgetIds!!.indices) {
            val layout: RemoteViews = buildLayout(context, appWidgetIds[i])
            appWidgetManager!!.updateAppWidget(appWidgetIds[i], layout)
        }
        super.onUpdate(context, appWidgetManager, appWidgetIds)
    }
}
Run Code Online (Sandbox Code Playgroud)

切换暗模式时不会调用 onUpdate。但是,当切换暗模式时,我似乎找不到在 AppWidgetProvider 中调用的任何方法,因此我不确定在哪里调用新的布局构建,甚至不知道如何检测何时需要更改。

任何帮助将非常感激。

android android-widget kotlin android-dark-theme

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

从导航列表中更改代码中的ActionBar背景颜色

我想在用户选择导航列表中的选择时更改操作栏背景的颜色.

目前,我的代码如下所示:

@Override
    public boolean onNavigationItemSelected(int itemPosition, long itemId) {
        ColorDrawable colorDrawable = new ColorDrawable();
        ActionBar actionBar = getActionBar();
        if(itemPosition == 0)
        {
            colorDrawable.setColor(0xffFEBB31);
            actionBar.setBackgroundDrawable(colorDrawable);
            return true;
        }
        if(itemPosition == 1)
        {
            colorDrawable.setColor(0xff9ACC00);
            actionBar.setBackgroundDrawable(colorDrawable);
            return true;
        }
        return false;
    }
Run Code Online (Sandbox Code Playgroud)

但是,第一次在导航列表中选择itemPosition 1时,它会将ActionBar颜色更改为白色.

在此输入图像描述
第二次单击导航列表中的itemPosition 1时,我没有问题.

在此输入图像描述
谁能告诉我为什么会这样,以及如何解决问题?感谢您的帮助!

android android-actionbar

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

SheetJS:不要在 json_to_sheet 中包含标题

SheetJS文档显示的方式采取JSON对象,并将其转换为Excel工作表。从他们的例子:

var ws = XLSX.utils.json_to_sheet([
  {S:1,h:2,e:3,e_1:4,t:5,J:6,S_1:7},
  {S:2,h:3,e:4,e_1:5,t:6,J:7,S_1:8}
], {header:["S","h","e","e_1","t","J","S_1"]});
Run Code Online (Sandbox Code Playgroud)

默认情况下,头信息是 Object.keys。

输出在 excel 中如下所示:

输出

我的问题:从 Json_to_sheet 转换时如何省略标题?我不想要输出中的标题,只想要 Object.keys 顺序中的数字。

js-xlsx xlsx-js sheetjs

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