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

前端之家收集整理的这篇文章主要介绍了1.10 状态选择器: 就是一个xml配置文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<? xml version = "1.0" encoding = "utf-8" ?>
< selector xmlns:android = "http://schemas.android.com/apk/res/android" >
< item android:state_pressed = "true"
android:drawable = "@color/gray" /> <!-- pressed :当前条目被按下时显示指定图形-->
< item android:state_focused = "true"
android:drawable = "@color/gray" /> <!-- focused:获取焦点的时候 -->
< item android:drawable = " @android:color/transparent " /> <!-- default :默认的图形-->
@H_502_353@
</ selector >
@H_502_353@
@H_502_353@
------------------------------------------------------------------------------------------------
@H_502_353@
<? xml version = "1.0" encoding = "utf-8" ?>
< LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:orientation = "vertical"
android:background="@drawable/home_item_selector"
android:gravity = "center"
>
< ImageView
android:id = "@+id/iv_item_icon"
android:src = "@drawable/app"
android:layout_width = "55dip"
android:layout_height = "55dip"
/>
< TextView
android:id = "@+id/tv_item_name"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:text = "手机防盗"
android:textColor = "#000000"
android:textSize = "16sp"
/>
</ LinearLayout >
@H_502_353@
@H_502_353@
@H_502_353@
-------------------------------------------------------------------------------------------

public class MainActivity extends Activity {
private GridView gv_home ;
private String[] names = { "手机防盗" , "通讯卫士" , "软件管理" , "进程管理" , "流量统计" , "手机杀毒" ,
"系统优化" , "高级工具" , "程序设置" };
@H_502_353@
private int [] icons = { R.drawable. icon_safe_selector ,R.drawable. icon_call_selector ,
R.drawable. icon_app_selector ,R.drawable. icon_task_selector ,R.drawable. icon_net_selector ,R.drawable. icon_trojan_selector ,
R.drawable. icon_sys_selector ,R.drawable. icon_atools_selector ,R.drawable. icon_setting_selector };
@Override
protected void onCreate(Bundle savedInstanceState) {
super .onCreate(savedInstanceState);
setContentView(R.layout. activity_main );
gv_home =(GridView) findViewById(R.id. gv_home );
//填充界面
gv_home .setAdapter( new HomeAdapter());
//跳转模块界面
gv_home .setOnItemClickListener( new OnItemClickListener() {
@H_502_353@
@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 ;
@H_502_353@
}
}
});
}
/**
* 创建适配器
* @author Administrator
*
*/
private class HomeAdapter extends BaseAdapter{
@H_502_353@
@Override
public int getCount() {
return names . length ;
}
@Override
public View getView( int position,View convertView,ViewGroup parent) {
//创建填充器
View view = View.inflate(getApplicationContext(),R.layout. grid_home_item , null );
ImageView iv_item_icon=(ImageView) view.findViewById(R.id. iv_item_icon );
TextView tv_item_name=(TextView) view.findViewById(R.id. tv_item_name );
iv_item_icon.setImageResource( icons [position]);
tv_item_name.setText( names [position]);
return view;
}
@H_502_353@
@Override
public Object getItem( int position) {
// TODO Auto-generated method stub
return null ;
}
@H_502_353@
@Override
public long getItemId( int position) {
// TODO Auto-generated method stub
return 0;
}
@H_502_353@
}
}
@H_502_353@

@H_502_353@

猜你在找的XML相关文章