2012-01-05 18 views
1

香港专业教育学院的文本颜色得到我的邮件相册类:更改Android图库

public class sub_gallery extends Gallery { 

public sub_gallery(Context ctx, AttributeSet attrSet) { 
    super(ctx, attrSet); 
    // TODO Auto-generated constructor stub 
} 

private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2){ 
     return e2.getX() > e1.getX(); 
    } 

@Override 
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY){ 
    int kEvent; 
    if(isScrollingLeft(e1, e2)){ //Check if scrolling left 
    kEvent = KeyEvent.KEYCODE_DPAD_LEFT; 
    } 
    else{ //Otherwise scrolling right 
    kEvent = KeyEvent.KEYCODE_DPAD_RIGHT; 
    } 
    onKeyDown(kEvent, null); 
    return true; 
} 
} 

和IM调用它像这样:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_gallery_item, new ArrayList<String>()); 
    adapter.add("text1"); 
    adapter.add("text2"); 
    adapter.add("text3"); 
    adapter.add("text4"); 
sub_gallery g = (sub_gallery) findViewById(R.id.sub_gal); 
    g.setAdapter(adapter); 

而且我的布局是如下:

<com.interfacetesting.android.email.sub_gallery 
     android:id="@+id/sub_gal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#d0d0d0" 
     android:layout_marginTop="10dp" 
     android:gravity="center_horizontal" 
     android:spacing="100px" 
     /> 

一切都按需要工作,但我无法弄清楚如何改变画廊(在阵列中)为我的生活文本颜色..

任何帮助,将不胜感激:d

感谢

+0

http://stackoverflow.com/questions/5732695/how-to-set-text-color-in-array-adapter在Android中没有帮助? – TryTryAgain 2012-01-05 18:00:21

+0

我不认为我可以实现他们在那个话题中说的一样..我试过了,没有运气。 – n388mm 2012-01-05 19:13:50

+0

这是怎么回事:http://stackoverflow.com/questions/5177056/overriding-android-arrayadapter和/或这个:http://www.coderanch.com/t/488673/Android/Mobile/styling-items-ListView – TryTryAgain 2012-01-05 21:21:47

回答

0

您是否尝试过使用了android:文字颜色= “#000000” 属性?

+0

是的,它不工作(我认为),因为我在我的layout.xml中调用该库作为 n388mm 2012-01-05 19:05:33

0

我试图做到这一点,而我发现的工作是用自定义项目布局替换android.R.layout.simple_gallery_item,例如, R.layout.gallery_item,如下所示:

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

<TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="30dp" 
    android:maxLines="1" 
    android:textColor="@color/gallery_item_color" 
/> 

然后创建一个res/color/gallery_item_color.xml

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_selected="true" 
      android:color="#ffadff2f"/> 
    <item android:state_selected="false" 
      android:color="#ffbebebe"/> 
</selector>