如何在listContainer的item(text)中设置setbackgr为图形里的xml文件。
我试了很多次,颜色也可以设置,就是死活不能设置xml背景图。要么点击退出,要么没有反应。
公共类型在开始(名字){
超级.onStart(intent);
超级.setUIContent(ResourceTable.Layout_ability_main);
// mSelectedText.setBackground(shapeElement);
// //初始化设置、初始化数据
initLayout_listcontainer1();
ListContainer listContainer = (ListContainer) findComponentById(ResourceTable.Id_list_container1);
listContainer.se
titemClickedListener ((容器,组件,位置,id)->
{
StatisticsLimit item = (StatisticsLimit) listContainer.getItemProvider().getItem(position);
新的 ToastDialog(这个)
.setText( "你长按:" + item.getLimit_date())
.setAlignment(LayoutAlignment.CENTER)
。显示();
set_listcontainer1_item_background(假);
组件 newsTypeText = component.findComponentById(ResourceTable.Id_statisticslimit_title);
if (newsTypeText instanceof Text) {
mSelectedText = (文本) newsTypeText;
}
set_listcontainer1_item_background(真);
}) ;
}
自定义类型initLayout_listcontainer1
()
{
ListContainer listContainer = (ListContainer) findComponentById (ResourceTable.Id_list_container1) ;
列表< StatisticsLimit > list_data1 = getData () ;
StatisticsLimitProvider statisticsLimitProvider = new StatisticsLimitProvider (list_data1, this ) ;
列表容器。setItemProvider (statisticsLimitProvider) ;
}
ArrayList < StatisticsLimit > Data ( ) {
ArrayList < StatisticsLimit > list = new ArrayList <> () ;
列表。add ( new StatisticsLimit( "今日" )) ;
列表。add ( new StatisticsLimit( "明日" )) ;
返回列表;
}
自定义set_listcontainer1_item_background
(布尔亮点){
ShapeElement listitembackgroundFocus = new ShapeElement () ;
列表项背景焦点。setRgbColor (新RgbColor( 108 , 166 , 205 )) ;
ShapeElement listitembackgroundNofocus = new ShapeElement () ;
列表项背景无焦点。setRgbColor (新RgbColor( 135 , 206 , 255 )) ;
if (mSelectedText == null ) {
返回;
}
如果(焦点){
mSelectedText。setTextColor ( new Color(Color.getIntColor( "#27408B" ))) ;
// mSelectedText . setBackground (listitembackgroundFocus) ;
ShapeElement shapeElementColor2 = new ShapeElement ( this , ResourceTable.Graphic_today) ;
mSelectedText。设置背景( shapeElementColor2 );
} 无论如何{
mSelectedText。setTextColor ( new Color(Color.getIntColor( "#999999" ))) ;
mSelectedText。setBackground (listitembackgroundNofocus) ;
}
}