小编Mor*_*ton的帖子

android:后台selectableItemBackground无效

我尝试使用selectableItemBackgroundrecyclerview,我测试一个简单的演示,它的工作.

这是布局和风格:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?android:attr/selectableItemBackground">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="100dp"
            android:layout_height="100dp"
            app:srcCompat="@mipmap/ic_launcher" />

    </LinearLayout>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

样式:

 <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
Run Code Online (Sandbox Code Playgroud)

当我测试另一个项目时,它不起作用,我正在寻找一些解决方案,其中一个解决方案可能是风格.

但解决方案的风格是Theme.AppCompat.Light.NoActionBar,我也使用它.

这是我的项目布局,有人能告诉我为什么吗?

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?android:attr/selectableItemBackground">

    <ImageView
        android:id="@+id/image"
        android:layout_width="15dp"
        android:layout_height="15dp"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="0dp"
        android:src="@drawable/pink_circle" />

</RelativeLayout>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

样式:

 <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview

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

如果我无法获得上下文我怎么能像Picaso一样使用?

我使用firbase-ui显示一个recyclerView,它扩展了Activity,就像这样:

FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<ChatItem, ExpenseHolder>
                (ChatItem.class, R.layout.chat_room_list, ExpenseHolder.class, secondRoot) {
            @Override
            protected void populateViewHolder(ExpenseHolder viewHolder, ChatItem chatItem, int position) {
                viewHolder.setValues(chatItem);
            }
        };
        recyclerChat.scrollToPosition(adapter.getItemCount() - 1);//just let the latest data below
        //recyclerChat.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL));//????
        recyclerChat.setAdapter(adapter);

        LinearLayoutManager manager = new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerChat.setLayoutManager(manager);
Run Code Online (Sandbox Code Playgroud)

这是我的ExpenseHolder,我发现它必须是静态的,否则会导致崩溃

    public static class ExpenseHolder extends RecyclerView.ViewHolder {
            private final TextView textRightMsg;
            private final TextView textLeftMsg;
            private final TextView rightTime;
            private final ImageView rightImage;

            public ExpenseHolder(View itemView) {
                super(itemView);

                textRightMsg = (TextView) itemView.findViewById(R.id.textRight);
                textLeftMsg = …
Run Code Online (Sandbox Code Playgroud)

android firebase picasso firebase-realtime-database

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

片段回到最后,屏幕是白色的

我有一个,它下面MainActivity有很多。Fragment

我设置了返回机制transaction.addToBackStack(null);

函数是这样的:

public void switchFragment(Fragment fragment) {
    FragmentManager manager = getSupportFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    transaction.replace(R.id.mainFrame, fragment, null);
    transaction.addToBackStack(null);
    transaction.commit();
}
Run Code Online (Sandbox Code Playgroud)

我的问题是当我单击后退按钮到底时,它FrameLayout是白色的 白屏

我尝试添加

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {    
        if (mainFrame==null)
            return super.onKeyDown(keyCode, event);
    }
}
Run Code Online (Sandbox Code Playgroud)

它不起作用。Fragment当我回拨到最后时如何避免出现白屏?任何帮助都会很棒!

android

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

如何在每个项目的微调器之间设置分隔符?

我正在寻找一些解决方案并尝试完成它.分频器仍然没有显示出来.

我在styles.xml中为我的主题设置了样式:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Others theme here. -->
    <item name="android:dropDownListViewStyle">@style/mySpinnerStyle</item>
</style>
Run Code Online (Sandbox Code Playgroud)

这是mySpinnerStyle

<style name="mySpinnerStyle" parent="android:Widget.ListView.DropDown">
    <item name="android:divider">#00ff00</item>
    <item name="android:dividerHeight">1dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)

这是我的微调器的片段代码:

Spinner chooseDate = (Spinner) view.findViewById(R.id.chooseDate);

String[] date_group = dateList.toArray(new String[dateList.size()]);
            ArrayAdapter<String> itemDate = new ArrayAdapter<String>(getActivity(), R.layout.spinner, date_group);
            itemDate.setDropDownViewResource(R.layout.spinner);
            chooseDate.setAdapter(itemDate);
Run Code Online (Sandbox Code Playgroud)

这是我的微调器布局xml:

<Spinner
            android:theme="@style/mySpinnerStyle"
            android:spinnerMode="dialog"
            android:layout_gravity="center"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="16dp"
            android:id="@+id/chooseDate"
            android:layout_width="match_parent"
            android:layout_height="38dp"
            android:background="@drawable/spinner_arrow" />
Run Code Online (Sandbox Code Playgroud)

然后R.layout.spinner xml是这样的:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:textSize="22dp"
    android:theme="@style/mySpinnerStyle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:gravity="center"
    android:paddingRight="40dp"
    android:singleLine="true" />
Run Code Online (Sandbox Code Playgroud)

我点击我的微调器显示对话框,最后没有分隔符... 在此输入图像描述

我为我的微调器设置了样式,但我不能显示分隔符.我不知道为什么?

任何帮助,将不胜感激 .谢谢你的支持.

清单使用我的AppTheme:

<application
    android:allowBackup="true"
    android:icon="@drawable/app_icon_512x512"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:name="android.support.multidex.MultiDexApplication">
Run Code Online (Sandbox Code Playgroud)

android android-spinner

0
推荐指数
2
解决办法
2197
查看次数

npm install -g在卸载react-native-cli时不起作用?

我正在尝试卸载用于反应本地项目的“ react-native-cli”!但我不能这样做!我的环境是mac

到目前为止,这是我所做的!

不管我输入npm uninstall -g react-native-cli还是输入sudo npm uninstall -g react-native-cli

终端显示: up to date in 0.041s

在此处输入图片说明

当我键入时react-native init projectName,它仍然创建项目。

我认为该命令react-native init不起作用。

有人知道如何卸载react-native-cli吗?

提前致谢。

npm react-native

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

如何将两个数组与对象进行比较?

我将 id 与两个带有对象的数组进行比较。

这是我的功能:

array1 = [
{ id: 1 },
{ id: 2 },
{ id: 3 }
];

array2 = [
{ id: 1 },
{ id: 2 },
{ id: 3 }
];

const compareFunction = (array1, array2) => {
  array2.map((allValue) => {
    array1.map((value) => {
      allValue.selected = value.id === allValue.id;
    });
  })

 return array2;
}
Run Code Online (Sandbox Code Playgroud)

我想我会得到array2喜欢的

[{ id: 1, selected: true }, { id: 2, selected: true },{ id: 3, selected: true }]
Run Code Online (Sandbox Code Playgroud)

但实际上 …

javascript

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