【发布时间】:2013-04-04 21:14:57
【问题描述】:
我试图让我的 TextViews 和 ImageView 显示在我添加了 StateListDrawable 的 LinearLayout 之上。我这样创建按钮:
protected StateListDrawable generateButton(String[] colors, String[] selectColors, String strokeColor, int strokewidth)
{
int[] iColors = CurrentTheme.getIntColorArrayFromStringArray(colors);
GradientDrawable gd = new GradientDrawable(Orientation.TL_BR, iColors);
gd.setCornerRadius(10);
gd.setStroke(strokewidth, Color.parseColor(strokeColor));
int[] iSelectColors = CurrentTheme.getIntColorArrayFromStringArray(selectColors);
GradientDrawable sgd = new GradientDrawable(Orientation.TL_BR, iSelectColors);
sgd.setCornerRadius(10);
sgd.setStroke(strokewidth, Color.parseColor(strokeColor));
StateListDrawable slDrawable = new StateListDrawable();
slDrawable.addState(new int[] { android.R.attr.state_pressed }, sgd);
slDrawable.addState(StateSet.WILD_CARD, gd);
return slDrawable;
}
在我的活动中,我将这个可绘制对象添加到这样的线性布局中:
_topMenuButton.setBackgroundDrawable(_theme.getPrimaryButtonDrawable());
布局包含在我的 Activity 的内容视图中的以下行中:
<include layout="@layout/inc_button_menu" android:id="@+id/second_menu_button" />
其中又包含一个 LinearLayout,其中包含一个 ImageView 和两个 TextView。
当我尝试从 LinearLayout(我在我的 Activity 中添加 StateListDrawable)获取 TextViews 并向其中添加 Text 时,文本不会显示。 ImageView 也是如此。我不确定如何让这些视图显示出来。
非常感谢任何帮助。
【问题讨论】:
标签: android textview imageview statelistdrawable