小编Har*_*ani的帖子

RecyclerView onClick

有没有人使用RecyclerView找到一种方法来设置一个onClickListener项目RecyclerView?我想为每个项目的每个布局设置一个监听器,但这似乎有点太麻烦我确信有一种方法RecyclerView可以听取这个onClick事件,但我无法弄明白.

android onclick onclicklistener android-recyclerview

544
推荐指数
24
解决办法
54万
查看次数

如何在Genymotion虚拟设备上安装Google框架(Play,Accounts等)?

我目前正在尝试Genymotion和男孩,它比ADT模拟器快得多.

但我需要安装Google Play才能将一些应用下载到其中.我该怎么做呢?

android android-virtual-device google-play-services genymotion

344
推荐指数
7
解决办法
43万
查看次数

如何对HashSet进行排序?

对于列表,我们使用该Collections.sort(List)方法.如果我们想要排序HashSet怎么办?

java sorting collections set hashset

92
推荐指数
9
解决办法
20万
查看次数

EditText光标和指针颜色为android 5.0以下

我试图更改EditText光标指针颜色(从原色蓝色到白色),但没有解决方案适用于我的项目.我试图开发演示项目,其中相同的代码工作正常.这段代码适用于> = android 5.0

我不知道,我的值会覆盖哪个属性.我有两个选项可以解决这个问题: -
1.找到控制该颜色值的属性.
2.页面加载时(在onViewCreated中)通过java代码更改颜色值.

请建议如何解决此问题.

styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="my_text_layout_style">

        <item name="android:textColor">#FFF</item>
        <item name="android:textColorHint">#FFF</item>

        <item name="colorAccent">#FFF</item>
        <item name="colorControlNormal">#FFF</item>
        <item name="colorControlActivated">#FFF</item>

        <item name="colorControlHighlight">#FFF</item>

    </style>



    <style name="my_edit_text_style">
        <item name="colorAccent">#FFF</item>
        <item name="android:editTextStyle">@style/MyEditTextStyle</item>
    </style>

    <style name="MyEditTextStyle" parent="Widget.AppCompat.EditText" />
</resources>
Run Code Online (Sandbox Code Playgroud)

layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@color/base_disable_btn_bg_color"
    android:orientation="vertical">

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:hint="just a hint"
        app:hintTextAppearance="@style/my_text_layout_style"
        android:theme="@style/my_text_layout_style"
        android:layout_height="wrap_content">

        <android.support.design.widget.TextInputEditText
            android:layout_width="match_parent"
            android:theme="@style/my_edit_text_style"
            android:layout_height="wrap_content" />

    </android.support.design.widget.TextInputLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

试图以编程方式添加视图但没有成功

AppLinearLayout appLinearLayout = (AppLinearLayout) view.findViewById(R.id.some_id);
EditText editText = new EditText(new ContextThemeWrapper(getContext(), …
Run Code Online (Sandbox Code Playgroud)

android android-edittext android-textinputedittext

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

如何在对话框上添加进度条

每当我想在我的应用程序中显示进度条时,我调用此方法,此方法将ProgressBar添加到我的布局中.

问题:我想在Dialog上显示此进度条,但Dialog始终显示在上面.这种情况可以做些什么?

public static void showProgressBar(@NonNull final Activity activity) {
    try {
        if (activity == null) {
            LogManager.printStackTrace(new NullActivityException());
            return;
        }
        View view = activity.findViewById(android.R.id.content);
        if (view == null) {
            LogManager.printStackTrace(new NullPointerException("content view is null"));
            return;
        }
        View rootView = activity.findViewById(android.R.id.content).getRootView();
        if (rootView == null || !(rootView instanceof ViewGroup)) {
            LogManager.printStackTrace(new NullPointerException("rootView is null or not an instance of ViewGroup"));
            return;
        }
        final ViewGroup layout = (ViewGroup) rootView;

        final ProgressBar progressBar = new ProgressBar(activity);
        progressBar.setIndeterminate(true);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) …
Run Code Online (Sandbox Code Playgroud)

android dialog android-progressbar

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

带有动画的Android Recycler视图适配器过滤器

我正在尝试优化Android中的RecyclerView Adapter的过滤方法.该列表用作ArrayList.我看过这篇文章但他们每次都会从原始列表中过滤掉.

示例:如果字符串'a'有10个结果,则用户输入'm','am'结果是'a'结果的子集(results.size()<= 10).

我在这个问题上有三点要问,

  1. 我可以使用ArrayMap优化HashMap内存吗?我应该在String中使用逗号分隔位置而不是Integer对象数组或使用int原始数组的任何方式吗?
  2. 我没有在这个结果中得到任何动画,如何得到它?(我notifyItemInserted还在使用动画)
  3. 在Hashmap中应该保留多少数据,直到2个字符或者应该根据结果列表大小?
我很高兴知道除了这些要点之外,在这个代码中是否可以做得更好.

在下面的代码中,mList用于onBindViewHolder方法中.copyList始终包含所有数据(不对其进行插入或删除).

class MyFilter extends Filter {


        /**
         * 1. check do we have search results available (check map has this key)
         * 2. if available, remove all rows and add only those which are value for that key (string)
         * 3. else check do we have any key available starting like this, s=har, already available -ha then it can be reused
         *
         * @param constraint …
Run Code Online (Sandbox Code Playgroud)

android android-filterable recycler-adapter android-recyclerview

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

反应原生资源问题

我是一名Android应用程序开发人员,并在过去一个月开始研究React-Native.我有疑问,对于那些我无法找到解决方案的人:

  1. 做反应本机使用sp而不是dpfont-size,如果我们想使用dp的font-size怎么办?

  2. 我想提供hdpi,xhdpixxhdpi梦诗的布局,如何做到这一点?

  3. 如何为7英寸平板电脑,10英寸平板电脑和手机提供单独的尺寸?出于某种目的,我想为react-native实现isDeviceTablet()方法,该怎么做?

android android-screen-support react-native

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

Android Retrofit 日志不显示

改造不打印日志。日志级别设置为详细。也尝试过 HttpLoggingInterceptor。

使用这些等级

compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
Run Code Online (Sandbox Code Playgroud)

代码

OkHttpClient httpClient = new OkHttpClient();
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
httpClient.newBuilder().connectTimeout(6, TimeUnit.MINUTES)
                .readTimeout(6, TimeUnit.MINUTES)
                .writeTimeout(6, TimeUnit.MINUTES)
                .addInterceptor(new Interceptor() {
                    @Override
                    public Response intercept(Chain chain) throws IOException {
                        Request original = chain.request();
                        Request.Builder requestBuilder = original.newBuilder()
                                .header("Content-Type", "application/json")
                                .header("Authorization", "aDRF@F#JG_a34-n3d")
                                .method(original.method(), original.body());
                        Request request = requestBuilder.build();
                        return chain.proceed(request);
                    }
                })
    .addInterceptor(httpLoggingInterceptor);


return httpClient;
Run Code Online (Sandbox Code Playgroud)

logging android retrofit2 okhttp3

5
推荐指数
3
解决办法
7402
查看次数

在动态交付模块中使用时应用模块尺寸/颜色的值不正确

我有应用程序模块和一个名为“聊天”的动态模块。我有一个布局和片段驻留在聊天模块中,在布局中有一个android:textSize="@dimen/sp20"书面的。Dimen 是在 app 模块中定义的,因为它在我运行时显示的文本大小不正确。我调试了一下,它等于12sp(xxhdpi设备为36)。

我尝试以编程方式使用 dimen 但结果相同。( landing_page_toolbar_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(com.sendbird.R.dimen.sp20))) 。小心使用应用模块包中的“R”。

当我在聊天模块中定义相同的值时,它完美地工作。但这对于我们的场景是不可行的。我有大量的字符串、尺寸、颜色资源,并在 app 模块中编写了多种配置。请分享可行的解决方案。

附上截图以便更好地理解。基于反射的结果比较

android dimension android-resources dynamic-delivery dynamic-feature-module

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

android 中的 SVG/VectorDrawable 问题

我在我的 Android 项目中使用了 svg 文件。Android 4.4 或更低版本存在问题。我已经尝试过这些解决方案

  1. app:srcCompat,
  2. vectorDrawables.useSupportLibrary = true 在 gradle 文件和
  3. AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);BaseActivity.
除了 gridview,图像不会显示在 app 中

svg android android-support-library android-5.0-lollipop android-vectordrawable

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