小编Kuv*_*uva的帖子

Android N以编程方式更改语言

我发现非常奇怪的错误只能在Android N设备上重现.

在浏览我的应用程序时,有可能改变语言.这是改变它的代码.

 public void update(Locale locale) {

    Locale.setDefault(locale);

    Configuration configuration = res.getConfiguration();

    if (BuildUtils.isAtLeast24Api()) {
        LocaleList localeList = new LocaleList(locale);

        LocaleList.setDefault(localeList);
        configuration.setLocales(localeList);
        configuration.setLocale(locale);

    } else if (BuildUtils.isAtLeast17Api()){
        configuration.setLocale(locale);

    } else {
        configuration.locale = locale;
    }

    res.updateConfiguration(configuration, res.getDisplayMetrics());
}
Run Code Online (Sandbox Code Playgroud)

这段代码非常适合我的游览活动(通过recreate()调用),但在所有下一个活动中,所有String资源都是错误的.屏幕旋转修复它.我该怎么办这个问题?我应该以不同方式更改Android N的区域设置,还是只是系统错误?

PS这是我发现的.首次启动MainActivity(在我的巡演之后)Locale.getDefault()是正确的,但资源是错误的.但在其他活动中,它给了我错误的Locale和来自此语言环境的错误资源.旋转屏幕(或可能是其他一些配置更改)Locale.getDefault()是正确的.

java android android-7.0-nougat

52
推荐指数
3
解决办法
3万
查看次数

Android创建BitmapDescriptor异常

我正在编写一个应用程序,可以使用谷歌地图和标记.我的任务是在谷歌地图上创建和显示一些标记.标记中包含自定义图像和文本.数据从服务器加载,我需要每次用户移动谷歌地图相机时显示新的数据量.所以我使用android-maps-utils:0.4.3库来创建自定义Bitmap(使用IconGenerator),然后从中创建BitmapDescriptor.以下是代码的一部分:

  googleMap.clear()

        LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        IconGenerator clusterIconGenerator = new IconGenerator(getActivity());
        View clusterView = layoutInflater.inflate(R.layout.marker_cluster_view, null, false);
        clusterIconGenerator.setContentView(clusterView);
        clusterIconGenerator.setBackground(ContextCompat.getDrawable(getActivity(), R.drawable.mark_normal_grey));

        List<Cluster> clusters = result.getResult();  // server data

        for (Cluster cluster : clusters) {
            Bitmap bitmap = clusterIconGenerator.makeIcon(String.valueOf(cluster.getOffersCount()));

            Marker marker = googleMap.addMarker(new MarkerOptions()
                    .position(new LatLng(cluster.getLocation().getLatitude(), cluster.getLocation().getLongitude()))
                    .icon(BitmapDescriptorFactory.fromBitmap(bitmap))  // crash here
                    .anchor(0.5f, 0.5f));

            markerClusterMap.put(marker, cluster);
        }
Run Code Online (Sandbox Code Playgroud)

一切都很好,除了应用程序崩溃有时(不经常)有2个不同的例外:

  java.lang.RuntimeException: Could not copy bitmap to parcel blob.
                                                                     at android.graphics.Bitmap.nativeWriteToParcel(Native Method)
                                                                     at android.graphics.Bitmap.writeToParcel(Bitmap.java:1541)
                                                                     at com.google.android.gms.maps.model.a.c.a(:com.google.android.gms:237)
                                                                     at com.google.android.gms.maps.internal.h.a(:com.google.android.gms:227)
                                                                     at com.google.android.gms.maps.internal.j.a(:com.google.android.gms:183)
                                                                     at com.google.android.gms.maps.internal.CreatorImpl.a(:com.google.android.gms:32)
                                                                     at com.google.android.gms.maps.internal.b.a(:com.google.android.gms:227)
                                                                     at …
Run Code Online (Sandbox Code Playgroud)

java android google-maps google-maps-markers google-maps-android-api-2

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

Android Oreo禁用EditText自动填充

我正在尝试对EditText除登录屏幕以外的所有内容禁用自动填充功能。还没有成功。longPress开启后,总会有“自动填充”选项editText。IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS rootView或IMPORTANT_FOR_AUTOFILL_NO完全无效。

有任何想法吗?谢谢。

android android-8.0-oreo android-autofill-manager

4
推荐指数
2
解决办法
3742
查看次数