我有我的邮件库课程:
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;
}
}
我这样称呼它:
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 :(得分:0)
您是否尝试过使用android:textColor =&#34;#000000&#34;属性?
答案 1 :(得分: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>