是否可以通过列表选择器将自定义背景应用于每个Listview项?
默认选择器指定@android:color/transparent了state_focused="false"大小写,但将其更改为某个自定义drawable不会影响未选中的项目.Romain Guy似乎在这个答案中建议这是可能的.
我目前正在通过在每个视图上使用自定义背景并在选择/聚焦项目时隐藏它来实现相同的效果,以便显示选择器,但是在一个地方将所有这些都定义为更优雅.
作为参考,这是我用来试图让它工作的选择器:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="false"
android:drawable="@drawable/list_item_gradient" />
<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
<item android:state_focused="true" android:state_enabled="false"
android:state_pressed="true"
android:drawable="@drawable/list_selector_background_disabled" />
<item android:state_focused="true" android:state_enabled="false"
android:drawable="@drawable/list_selector_background_disabled" />
<item android:state_focused="true" android:state_pressed="true"
android:drawable="@drawable/list_selector_background_transition" />
<item android:state_focused="false" android:state_pressed="true"
android:drawable="@drawable/list_selector_background_transition" />
<item android:state_focused="true"
android:drawable="@drawable/list_selector_background_focus" />
</selector>
Run Code Online (Sandbox Code Playgroud)
这就是我设置选择器的方式:
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:listSelector="@drawable/list_selector_background" />
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助!
我正在开发一个应用程序,在我的主页上,我需要给徽标(imageview)提供发光和褪色效果动画我尝试了很多,但是找不到如何给出发光效果动画,我知道onclick事件的发光效果请帮我解决这个问题提前谢谢
public class CustomView extends ImageView{
public CustomView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public CustomView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomView(Context context) {
super(context);
}
boolean drawGlow = false;
//this is the pixel coordinates of the screen
float glowX = 0;
float glowY = 0;
//this is the radius of the circle we are drawing
float radius = 20;
//this is the paint object which specifies the color and alpha level
//of …Run Code Online (Sandbox Code Playgroud)