小编HBG*_*HBG的帖子

新的Google即时和Google+卡界面

Google即时和Google +(Android)都使用类似卡片的界面.

在此输入图像描述

我想知道是否有人知道如何在Android上复制此界面.

它们都有非常有趣的动画来展示新卡片; 任何想法都会很棒.

android android-layout google-plus google-now

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

Android 自定义语言环境在黑暗模式(夜间模式)切换期间丢失

我们的应用程序要求我们能够根据用户选择更改语言,而不仅仅是依赖设备区域设置。这意味着我们必须实现一种方法来在用户进行此选择时包装上下文并在每个 Activity 中注入指定的语言。

    @Override
    protected void attachBaseContext(Context newBase) {
        super.attachBaseContext(LocaleProvider.getAppLocale().wrapContextWithAppLanguage(newBase));
    }
Run Code Online (Sandbox Code Playgroud)
fun wrapContextWithAppLanguage(context: Context): Context {
        val userLocale: Locale = localeProvider.getCurrentStoreLanguage(context)
        Locale.setDefault(userLocale)

        return when {
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.N -> updateResourcesLocale(
                context,
                userLocale
            )
            else -> updateResourcesLocaleLegacy(context, userLocale)
        }
    }

    @TargetApi(Build.VERSION_CODES.N)
    private fun updateResourcesLocale(context: Context, locale: Locale): Context {
        val configuration = context.resources.configuration
        configuration.setLocale(locale)
        return context.createConfigurationContext(configuration)
    }

    private fun updateResourcesLocaleLegacy(context: Context, locale: Locale): Context {
        val resources = context.resources
        val configuration = resources.configuration
        configuration.setLocale(locale)
        resources.updateConfiguration(configuration, resources.displayMetrics)
        return context
    }
Run Code Online (Sandbox Code Playgroud)

这在过去对我们很有效,但现在我们已经实施了暗模式,我们注意到在使用 appcompat …

android android-appcompat android-support-library android-night-mode

9
推荐指数
0
解决办法
896
查看次数

Dagger2 @Binds 方法的参数类型必须可分配给具有接口和实现的返回类型

我有一个类实现了java.util.function.Function我想注入的接口,以便在另一个使用 Dagger2 的类中使用:

class MyUsefulClass @Inject constructor() : Function<List<String>, String> {

    override fun apply(lines: List<String>): String {
        // Do stuff 
        return ""
    }
}
Run Code Online (Sandbox Code Playgroud)

通常,我会@Binds在模块类中声明一个声明,如下所示:

@Module
interface MyModule {

    @Binds
    fun provideMyUsefulClass(concretion: MyUsefulClass): Function<List<String>, String>
}
Run Code Online (Sandbox Code Playgroud)

这种做法使我受益匪浅的所有其他类我已经在我的项目实现这个接口,但是在这一个实例中,我被错误消息映入眼帘:

@Binds methods' parameter type must be assignable to the return type…

有趣的是,将类的返回类型和@Binds声明更改为Function<MutableList<String>, String>fromFunction<List<String>, String>有效,一切都可以正常编译。

我在这里缺少什么?错误消息显然是不真实的。是否有一些我不知道的重大问题?

android kotlin dagger-2

3
推荐指数
1
解决办法
3182
查看次数

在 Flutter 包中使用自定义图标字体会显示问号而不是自定义图标

我有一个由许多不同的 Dart 和 Flutter 包组成的应用程序。事实证明这很有用,因为我能够将字体、颜色和小部件等内容移动到一个独立的样式指南包中,然后我们可以在所有内容中使用它我们的其他应用程序。

\n

在包中使用自定义字体在Flutter 中的工作方式略有不同,因为我们需要将assets目录添加为子目录lib而不是同级目录:

\n

将资源添加到包中

\n

\xe2\x80\xa6 然后像这样注册这些资产pubspec.yaml

\n
assets:\n - packages/receipt_widget/assets/fonts/my_font.ttf\n // other asset declarations\n\n
Run Code Online (Sandbox Code Playgroud)\n

对于自定义字体和图标(png、jpg 等)来说,这完全可以正常工作。我的问题是,同样的方法不适用于自定义图标字体

\n

脚步:

\n
    \n
  • 使用IcoMoonFlutter Icon生成自定义图标字体
  • \n
  • 将生成的字体放入assets/fonts如上所示的目录中
  • \n
  • 将生成的dart文件放入lib文件夹中
  • \n
  • 在代码中引用自定义图标并将其放入Icon小部件中,如下所示:
  • \n
\n
Icon(MyFontIcon.ic_heart);\n
Run Code Online (Sandbox Code Playgroud)\n

为了安全起见,我然后flutter clean在部署干净的版本之前从设备/模拟器运行并卸载应用程序。\n然后我留下一个问号而不是引用的图标。

\n

注意。当直接在 Flutter 应用程序中而不是在包中使用时,相同的图标可以正常工作。

\n

flutter flutter-dependencies pubspec

3
推荐指数
1
解决办法
2757
查看次数

旋转设备后从DialogFragment接收回调时,片段未附加到Activity

我正在创建一个应用程序,允许用户从图库上载图像或使用设备相机拍摄照片。单击适当的按钮时,将出现一个对话框,用户可以选择“拍摄照片”或“选择图像”。一切正常,问题是当我在对话框显示在屏幕上时旋转设备,然后选择一个选项,应用程序崩溃时IllegalStateException说我的片段未连接到活动。我已经包含了用于与目标片段进行通讯的对话框:

创建DialogFragment:

public void onClick() {
    // Display a Dialog for choice between pick/ take picture
    ListDialogFragment dialogFragment = ListDialogFragment.newInstance(R.string.take_photo, R.array.add_picture_options_array);
    dialogFragment.setTargetFragment(this, 0);
    dialogFragment.show(getFragmentManager(), "Moo");
}
Run Code Online (Sandbox Code Playgroud)

DialogFragment类:

public class ListDialogFragment extends DialogFragment {

private static final String TITLE_RESOURCE_ID = "title_resource_id";
private static final String ARRAY_RESOURCE_ID = "array_resource_id";

private DialogItemSelectedListener listener;

public interface DialogItemSelectedListener {
    void onTakePhotoSelected();

    void onSelectImageSelected();
}

public ListDialogFragment() {
    // Default empty constructor
}

public static ListDialogFragment newInstance(@StringRes final int titleResourceId, @ArrayRes final int arrayResourceId) …
Run Code Online (Sandbox Code Playgroud)

android android-fragments

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