我有一个带有gridview的日历,所以用小块(天)填充日历看起来像这样:
adapter = new GridCellAdapter(getApplicationContext(), R.id.calendar_day_gridcell, month, year);
R.id.calendar_day_gridcell分隔在xml文件中:
<Button
android:id="@+id/calendar_day_gridcell"
android:layout_gravity="center"
android:textColor="#000000"
android:background="@drawable/calendar_button_selector"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="45dip"
android:layout_height="45dip">
</Button>
calendar_button_selector是另一个xml文件:
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/calendar_bg_orange" /> <!-- pressed -->
<item
android:state_focused="true"
android:drawable="@drawable/calendar_bg_orange" /> <!-- focused -->
<item
android:drawable="@drawable/grid_cell_sajat" /> <!-- default -->
</selector>
在grid_cell_sajat,我有一个带有渐变等的形状。它的效果非常好。我怎样才能以编程方式完成这些工作?
int colorsxx[] = { 0xff393939 , 0xffffffff };
GradientDrawable g = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, colorsxx);
g.setStroke(3, Color.BLACK);
GradientDrawable g2 = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colorsxx);
g2.setStroke(3, Color.BLACK);
g.setBounds(10, 10, 10, 10);
StateListDrawable stld = new StateListDrawable();
stld.addState(new int[] {-android.R.attr.state_enabled}, g);
stld.addState(new int[] { android.R.attr.state_pressed }, g2);
adapter = new GridCellAdapter(getApplicationContext(), R.id.calendar_day_gridcell, month, year);
好'stld'是一个drawable,但是适配器需要一个整数。如何为适配器设置它,或以某种方式将其转换为“整数类型”?
提前致谢!
答案 0 :(得分:0)
很高兴它有所帮助, 所以答案是:你尝试将其设置为背景吗?应该适用于大多数(所有?)视图。使用view.setBackground(R.drawable.calendar_button_selector);我想calendar_button_selector需要在drawable文件夹中才能工作。