我有一个带有网格视图的日历,所以用小块(天)填充日历看起来像这样:
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' 是一个可绘制对象,但适配器需要一个整数。如何为适配器设置它,或者以某种方式将其转换为“整数类型”?
提前致谢!