小编use*_*993的帖子

如何动态地将按下的颜色更改为选择器的其他颜色?

这是我的列表选择器:(item_selector.xml)

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:drawable="@color/orange" />
    <item android:state_focused="true" android:drawable="@color/orange" />
    <item android:state_pressed="true" android:drawable="@color/orange" />
    <item android:drawable="@color/transparent" />
</selector>
Run Code Online (Sandbox Code Playgroud)

这是我的行列表(row_item.xml)

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/alarm_item_drawer_selector"
    >

    <ImageView 
        android:id="@+id/item_icon"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_centerHorizontal="true"
        android:paddingTop="5dp"
        android:paddingBottom="2dp"
        android:src="@drawable/ic_launcher"/>

    <TextView      
        android:id="@+id/item_title"
        style="@style/DrawerItemTextStyle"
        android:textColor="@color/text_drawer_item_selector"
        android:layout_centerHorizontal="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/item_icon" />

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

我想动态地将android:state_pressed ="true"android:drawable ="@ color/orange"改为其他颜色.我的目标是使每一行的按压颜色不同.有可能吗?

java android selector

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

为什么instantiateItem不调用而Vie​​wPager不起作用?

我尝试使用滑动图像进行简单的应用.我使用这篇文章http://www.androidbegin.com/tutorial/android-viewpager-gallery-images-and-texts-tutorial/.

这是我的xml with viewpager:main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <android.support.v4.view.ViewPager
        android:id="@+id/pages"
        android:layout_height="match_parent"
        android:layout_width="match_parent">
    </android.support.v4.view.ViewPager>

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

这是我的xml with image:item.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageView
        android:id="@+id/image"
        android:layout_gravity="center"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/ic_launcher" />

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

这是我的适配器:ViewerPagerAdapter.java

public class ViewerPagerAdapter extends PagerAdapter {

    private Context mContext;
    private ArrayList<CueModel> mArray;
    private LayoutInflater mInflater;
    private ImageView mImage;

    public ViewerPagerAdapter(Context _context){
        mContext = _context;

        mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }


    public void setArray(ArrayList<Bitmap> arr){
        mArray = arr;
    }

    @Override
    public int getItemPosition(Object object) {  
        return POSITION_NONE; …
Run Code Online (Sandbox Code Playgroud)

java android android-viewpager

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

标签 统计

android ×2

java ×2

android-viewpager ×1

selector ×1