【问题标题】:Ripple Effect doesn't work in listview涟漪效应在列表视图中不起作用
【发布时间】:2016-11-23 14:44:06
【问题描述】:

我在 android 中有一个可点击的列表视图,当我选择一个项目时涟漪效果正在工作,但我更改了我的样式文件以添加此行以在按钮中工作涟漪效果

<style name="InflorTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
         //other things
         <item name="colorControlHighlight">@color/ripple_material_dark</item>
    </style>

添加此行后,波纹效果在按钮中起作用,但在列表视图中不起作用。

有什么建议可以解决我的问题吗?

这是我的 stles 文件:

<resources>
    <style name="InflorTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="colorControlNormal">@color/colorAccent</item>
        <item name="colorControlHighlight">@color/ripple_material_dark</item>
    </style>
    <style name="InflorTheme" parent="InflorTheme.Base">
    </style>
    <style name="InflorTheme.Splash" parent="android:Theme">
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowBackground">@drawable/splash</item>
        <item name="android:windowNoTitle">true</item>
    </style>
</resources>

这是我的风格 v-21:

<resources>
    <style name="InflorTheme" parent="InflorTheme.Base">
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:windowContentTransitions">true</item>
        <item name="android:windowAllowEnterTransitionOverlap">true</item>
        <item name="android:windowAllowReturnTransitionOverlap">true</item>
        <item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
        <item name="android:windowSharedElementExitTransition">@android:transition/move</item>
    </style>
</resources>

这是我的列表视图:

<Mvx.MvxListView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/listBoletins"
            android:footerDividersEnabled="true"
            android:headerDividersEnabled="true"
            android:dividerHeight="1dp"
            android:textFilterEnabled="false"
            android:layout_weight="1"
            android:background="?android:attr/selectableItemBackground"
            local:MvxBind="ItemsSource Boletins; ItemClick BoletimClickCommand"
            local:MvxItemTemplate="@layout/boletinsitem" />

【问题讨论】:

    标签: android android-layout listview xamarin.android material-design


    【解决方案1】:

    将此添加到您在适配器中呈现的项目中。 android:foreground="?attr/selectableItemBackground" android:clickable="true" 在你看来

    【讨论】:

    • 我必须在哪里添加?在 ListView 中还是在布局中?
    • 嘿,我已经更新了我的答案。对不起,部分答案。
    • 得到了预期的结果,谢谢
    • @Tasneem,不,它没有
    【解决方案2】:

    为什么你把这么简单的事情弄得这么复杂。你应该使用 Listview 或“appcompat listview”而不是 MvxListView。并尝试根据你的要求改变你的风格。

    如果你对自定义列表视图有自己的限制,那么你应该像这样尝试。myview是你的布局视图

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.your_layout);
    
        View myView = findViewById(R.id.myView);
        int[] attrs = new int[]{R.attr.selectableItemBackground};
        TypedArray typedArray = getActivity().obtainStyledAttributes(attrs);
        int backgroundResource = typedArray.getResourceId(0, 0);
        myView.setBackgroundResource(backgroundResource);
    }
    

    并将这一行添加到您的 xml 文件中

    <android:background="?android:attr/selectableItemBackground">
    

    【讨论】:

      【解决方案3】:

      就这么简单

      <ListView
          ...
          android:drawSelectorOnTop="true"/>
      

      将在列表视图上启用涟漪效果。

      【讨论】:

        猜你喜欢
        • 2020-09-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-25
        • 1970-01-01
        • 2022-07-30
        • 1970-01-01
        相关资源
        最近更新 更多