xinyun94 2016-02-23 07:14 采纳率: 52.4%
浏览 1424

gridview item背景色的问题

这是布局代码:
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="11"
android:gravity="center_horizontal"
style="@style/firstTitleText"/>
android:id="@+id/gv_setrepeatmonth"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="auto_fit"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp">
  

<TextView 
    android:id="@+id/tv_confirm"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="确定"
    android:layout_gravity="right"
    android:layout_marginRight="20dp"
    style="@style/buttonText"/>

这是gridview item布局代码
<TextView
android:id="@+id/tv_date"
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25dp"
android:background="@drawable/textview_background_selector"
android:text="文字"

这里的background是一个点击变蓝色,不点击就是白色的selector

这是adapter getview方法代码
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final int p = position;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.addschedule_setrepeatmonthitem, null);
tv = (TextView) convertView.findViewById(R.id.tv_date);
convertView.setTag(tv);
}
if (clickTemp == position) {
// 已经进入,但是并没有修改背景色,修改下面背景色也无法改变模拟器上显示的item的背景色
Log.e("PPPPP+++CCCC", "ture");
tv.setBackgroundColor(R.color.red);
} else {
tv.setBackgroundColor(R.color.white);
}
tv.setText(String.valueOf(position+1));

    return convertView;
}

这是项目的theme:
<br> <item name="android:windowTitleSize">50dp</item><br> <item name="android:windowNoTitle">true</item><br> <item name="android:windowActionBar">false</item><br> <item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground</item><br>

接着配置适配器
initControl();
initDate();
adapter = new SetRepeatMonthAdapter(SetRepeatMonthActivity.this, arr);
gv_month.setSelector(new ColorDrawable(Color.TRANSPARENT));//取消GridView中Item选中时默认的背景色

    gv_month.setAdapter(adapter);


我不知道为什么,实现出来的效果是这样的
![图片说明](https://img-ask.csdn.net/upload/201602/23/1456211632_374437.png)
所有的item都是灰色的背景,而且我的activity不能全屏,有黑色的部分在那里
  • 写回答

1条回答 默认 最新

  • threenewbee 2016-03-06 22:07
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧