如图,点击主界面的“通信卫士”项目后显示黑名单拦截界面。顶部一个TextView显示标题,一个View显示分割条。
底部一个button用来添加黑名单。
中间一个listview用来显示已经设置的黑名单列表。
在页面加载时,读取数据中的黑名单列表,需要使用线程来做,并且在读取过程中一直显示进度条显示“正在加载中……”
因此进度条和listview有重叠,加载时显示进度条,加载完毕后设置其可见属性为不可见即可。
布局文件为:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<TextView style="@style/title_center_text"
android:text="通信卫士"/>
<View style="@style/splitter_view"/>
</LinearLayout>
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_alignParentBottom="true">
<LinearLayout
android:id="@+id/ll_callsafe_loading"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_centerHorizontal="true"
android:gravity="center">
<ProgressBar
android:layout_centerHorizontal="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
<TextView
android:text="正在加载中……"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
</LinearLayout>
<ListView
android:id="@+id/lv_blacknumbers"
android:layout_height="match_parent"
android:layout_width="match_parent">
</ListView>
<Button
android:id="@+id/bt_add_blacknumber"
android:text="添加黑名单"
android:textSize="20sp"
android:background="@drawable/bt_selector"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
</RelativeLayout>
</LinearLayout>
button的背景使用了selector:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/bt_pressed" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="@drawable/bt_selected" /> <!-- focused -->
<item android:drawable="@drawable/bt_normal" /> <!-- default -->
</selector>
bt_normal:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:radius="3dip" />
<solid android:color="#55ff00" />
<padding
android:bottom="3dip"
android:left="3dip"
android:right="3dip"
android:top="3dip" />
</shape>
bt_selected:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:radius="3dip" />
<solid android:color="#66ff02" />
<padding
android:bottom="3dip"
android:left="3dip"
android:right="3dip"
android:top="3dip" />
</shape>
bt_pressed:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<padding
android:left="5dip"
android:right="5dip"
android:top="8dip"
android:bottom="8dip"
></padding>
<solid
android:color="#676767"
></solid>
</shape>
默认效果图:
按下按钮的效果:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv_callsafe_item_name"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
<TextView
android:id="@+id/tv_callsafe_item_mode"
android:layout_alignParentRight="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
</RelativeLayout>
主要就两个TextView,一个用来显示黑名单号码,一个显示拦截模式。
最后,需要在MainActivity中添加代码:
case 1: //通信卫士
intent = new Intent(MainActivity.this, CallSafeActivity.class);
startActivity(intent);
break;
完整代码:
package com.example.mobilesafe;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
/**
* Created by sing on 13-12-24.
* desc:
*/
public class MainActivity extends Activity {
//activity_main中的gridview控件
private GridView gv_main;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gv_main = (GridView) findViewById(R.id.gv_main);
//为gv_main对象设置适配器,该适配器为每个item填充对应的数据
gv_main.setAdapter(new MainAdapter(this));
//为gv_main设置点击item的处理事件
gv_main.setOnItemClickListener(new AdapterView.OnItemClickListener() {
/**
* item点击事件
* @param adapterView
* @param view
* @param i
* @param l
*/
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = null;
switch (i) {
case 0: //手机防盗
intent = new Intent(MainActivity.this, LostProtectedActivity.class);
startActivity(intent);
break;
case 1: //通信卫士
intent = new Intent(MainActivity.this, CallSafeActivity.class);
startActivity(intent);
break;
case 7: //高级工具
intent = new Intent(MainActivity.this, AToolsActivity.class);
startActivity(intent);
break;
case 8: //设置中心
intent = new Intent(MainActivity.this, SettingCenterActivity.class);
startActivity(intent);
break;
}
}
});
}
}