1.10 状态选择器: 就是一个xml配置文件

前端之家收集整理的这篇文章主要介绍了1.10 状态选择器: 就是一个xml配置文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<? xml version = @H_502_23@"1.0" encoding = @H_502_23@"utf-8" ?>
< selector xmlns:android = @H_502_23@"http://schemas.android.com/apk/res/android" >
< item android:state_pressed = @H_502_23@"true"
android:drawable = @H_502_23@"@color/gray" /> <!-- pressed :当前条目被按下时显示指定图形-->
< item android:state_focused = @H_502_23@"true"
android:drawable = @H_502_23@"@color/gray" /> <!-- focused:获取焦点的时候 -->
< item android:drawable = @H_502_23@" @H_502_23@@android:color/transparent @H_502_23@" /> <!-- default :默认的图形-->

</ selector >


------------------------------------------------------------------------------------------------

<? xml version = @H_502_23@"1.0" encoding = @H_502_23@"@H_502_23@utf@H_502_23@-8" ?>
< LinearLayout xmlns:android = @H_502_23@"http://schemas.android.com/apk/res/android"
android:layout_width = @H_502_23@"match_parent"
android:layout_height = @H_502_23@"match_parent"
android:orientation = @H_502_23@"vertical"
android:background=@H_502_23@"@drawable/home_item_selector"
android:gravity = @H_502_23@"center"
>
< ImageView
android:id = @H_502_23@"@+id/iv_item_icon"
android:src = @H_502_23@"@drawable/app"
android:layout_width = @H_502_23@"55dip"
android:layout_height = @H_502_23@"55dip"
/>
< TextView
android:id = @H_502_23@"@+id/tv_item_name"
android:layout_width = @H_502_23@"wrap_content"
android:layout_height = @H_502_23@"wrap_content"
android:text = @H_502_23@"手机防盗"
android:textColor = @H_502_23@"#000000"
android:textSize = @H_502_23@"16sp"
/>
</ LinearLayout >



-------------------------------------------------------------------------------------------

public class MainActivity extends Activity {
private GridView gv_home ;
private String[] names = { "手机防盗" , "通讯卫士" , "软件管理" , "进程管理" , "流量统计" , "手机杀毒" ,
"系统优化" , "高级工具" , "程序设置" };

private int [] icons = { R.drawable. @H_502_23@icon_safe_selector ,R.drawable. @H_502_23@icon_call_selector ,
R.drawable. @H_502_23@icon_app_selector ,R.drawable. @H_502_23@icon_task_selector ,R.drawable. @H_502_23@icon_net_selector ,R.drawable. @H_502_23@icon_trojan_selector ,
R.drawable. @H_502_23@icon_sys_selector ,R.drawable. @H_502_23@icon_atools_selector ,R.drawable. @H_502_23@icon_setting_selector };
@Override
protected void onCreate(Bundle savedInstanceState) {
super .onCreate(savedInstanceState);
setContentView(R.layout. @H_502_23@activity_main );
gv_home =(GridView) findViewById(R.id. @H_502_23@gv_home );
//填充界面
gv_home .setAdapter( new HomeAdapter());
//跳转模块界面
gv_home .setOnItemClickListener( new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent,View view,
int position, long id) {
switch (position) {
case 8:
Intent intent_setting= new Intent(MainActivity. this ,SettingActivity. class );
startActivity(intent_setting);
break ;

}
}
});
}
/**
* 创建适配器
* @author Administrator
*
*/
private class HomeAdapter extends BaseAdapter{

@Override
public int getCount() {
return names . length ;
}
@Override
public View getView( int position,View convertView,ViewGroup parent) {
//创建填充器
View view = View.@H_502_23@inflate(getApplicationContext(),R.layout. @H_502_23@grid_home_item , null );
ImageView iv_item_icon=(ImageView) view.findViewById(R.id. @H_502_23@iv_item_icon );
TextView tv_item_name=(TextView) view.findViewById(R.id. @H_502_23@tv_item_name );
iv_item_icon.setImageResource( icons [position]);
tv_item_name.setText( names [position]);
return view;
}

@Override
public Object getItem( int position) {
// TODO Auto-generated method stub
return null ;
}

@Override
public long getItemId( int position) {
// TODO Auto-generated method stub
return 0;
}

}
}


原文链接:https://www.f2er.com/xml/299664.html

猜你在找的XML相关文章