【Android开发】网上商城
文章目录
【Android开发】网上商城一、开发环境需求二、系统功能设计三、运行结果1. 欢迎界面2. 搜索界面3. 登录界面四、主要代码1. HomeActivity.java2. activity_home.xml以上是主要代码,完整文件可点击链接下载一、开发环境需求
二、系统功能设计
三、运行结果
1. 欢迎界面
2. 搜索界面
3. 登录界面
四、主要代码
1. HomeActivity.java
代码如下:
package com.itau.jingdong.ui;import android.app.AlertDialog;import android.app.Dialog;import android.app.TabActivity;import android.content.DialogInterface;import android.content.DialogInterface.OnClickListener;import android.content.Intent;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.widget.RadioGroup;import android.widget.RelativeLayout;import android.widget.TabHost;import android.widget.RadioGroup.OnCheckedChangeListener;import com.itau.jingdong.AppManager;import com.itau.jingdong.R;import com.nostra13.universalimageloader.core.ImageLoader;//主页面public class HomeActivity extends TabActivity {//打印日志标记public static final String TAG = HomeActivity.class.getSimpleName();//定义一个单选按钮组 用于切换底部选项栏private RadioGroup mTabButtonGroup;private TabHost mTabHost;//选项卡组件//定义选项卡对应的类名public static final String TAB_MAIN = "MAIN_ACTIVITY";//主页public static final String TAB_SEARCH = "SEARCH_ACTIVITY";//查询public static final String TAB_CATEGORY = "CATEGORY_ACTIVITY";//分类public static final String TAB_CART = "CART_ACTIVITY";//购物车public static final String TAB_PERSONAL = "PERSONAL_ACTIVITY";//个人@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);AppManager.getInstance().addActivity(this);setContentView(R.layout.activity_home);findViewById();//绑定控件initView();}private void findViewById() {//绑定单选按钮组控件mTabButtonGroup = (RadioGroup) findViewById(R.id.home_radio_button_group);}private void initView() {//获取选项mTabHost = getTabHost();//定义响应的intent对象Intent i_main = new Intent(this, IndexActivity.class);Intent i_search = new Intent(this, SearchActivity.class);Intent i_category = new Intent(this, CategoryActivity.class);Intent i_cart = new Intent(this, CartActivity.class);Intent i_personal = new Intent(this, PersonalActivity.class);//将选项与对应页面加入tab项mTabHost.addTab(mTabHost.newTabSpec(TAB_MAIN).setIndicator(TAB_MAIN).setContent(i_main));mTabHost.addTab(mTabHost.newTabSpec(TAB_SEARCH).setIndicator(TAB_SEARCH).setContent(i_search));mTabHost.addTab(mTabHost.newTabSpec(TAB_CATEGORY).setIndicator(TAB_CATEGORY).setContent(i_category));mTabHost.addTab(mTabHost.newTabSpec(TAB_CART).setIndicator(TAB_CART).setContent(i_cart));mTabHost.addTab(mTabHost.newTabSpec(TAB_PERSONAL).setIndicator(TAB_PERSONAL).setContent(i_personal));//设置当前显示页mTabHost.setCurrentTabByTag(TAB_MAIN);//设置单选监听事件 根据单选项跳转至指定页面mTabButtonGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {public void onCheckedChanged(RadioGroup group, int checkedId) {switch (checkedId) {//主页面case R.id.home_tab_main:mTabHost.setCurrentTabByTag(TAB_MAIN);break;//查询页面case R.id.home_tab_search:mTabHost.setCurrentTabByTag(TAB_SEARCH);break;//分类页面case R.id.home_tab_category:mTabHost.setCurrentTabByTag(TAB_CATEGORY);break;//购物车页面case R.id.home_tab_cart:mTabHost.setCurrentTabByTag(TAB_CART);break;//用户信息页面case R.id.home_tab_personal:mTabHost.setCurrentTabByTag(TAB_PERSONAL);break;default:break;}}});}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {//加载菜单项getMenuInflater().inflate(R.menu.activity_menu, menu);return true;}//根据菜单项跳转至不同页面@Overridepublic boolean onOptionsItemSelected(MenuItem item) {// TODO Auto-generated method stubswitch (item.getItemId()) {case R.id.menu_about:break;case R.id.menu_setting:break;case R.id.menu_history:break;case R.id.menu_feedback:break;case R.id.menu_exit://启动退出页面对话框showAlertDialog("退出程序", "确定退出京东商城?", "确定", new OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stubAppManager.getInstance().AppExit(getApplicationContext());ImageLoader.getInstance().clearMemoryCache();}}, "取消", new OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stubdialog.dismiss();}});break;case R.id.menu_help:break;default:break;}return true;}//显示一个对话框 有两个按钮protected void showAlertDialog(String title, String message,String positiveText,DialogInterface.OnClickListener onPositiveClickListener,String negativeText,DialogInterface.OnClickListener onNegativeClickListener) {//创建一个含有确定 取消的 对话框new AlertDialog.Builder(this).setTitle(title).setMessage(message).setPositiveButton(positiveText, onPositiveClickListener).setNegativeButton(negativeText, onNegativeClickListener).show();//记得设置显示}}
2. activity_home.xml
代码如下:
<?xml version="1.0" encoding="utf-8"?><!--首页底部导航栏--><TabHost xmlns:android="/apk/res/android"android:id="@android:id/tabhost"android:layout_width="match_parent"android:layout_height="match_parent" ><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" ><FrameLayoutandroid:id="@android:id/tabcontent"android:layout_width="match_parent"android:layout_height="0.0dip"android:layout_weight="1.0"android:background="@drawable/android_layout_bg" /><TabWidgetandroid:id="@android:id/tabs"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="0.0"android:visibility="gone" /><RadioGroupandroid:id="@+id/home_radio_button_group"android:layout_width="match_parent"android:layout_height="55dp"android:layout_gravity="bottom"android:background="@drawable/main_navigation_background"android:gravity="center_vertical"android:orientation="horizontal" ><RadioButtonandroid:id="@+id/home_tab_main"style="@style/home_tab_bottom"android:background="@drawable/home_tab_background_selector"android:checked="true"android:drawableTop="@drawable/home_tab_main_selector" /><RadioButtonandroid:id="@+id/home_tab_search"style="@style/home_tab_bottom"android:background="@drawable/home_tab_background_selector"android:drawableTop="@drawable/home_tab_search_selector" /><RadioButtonandroid:id="@+id/home_tab_category"style="@style/home_tab_bottom"android:background="@drawable/home_tab_background_selector"android:drawableTop="@drawable/home_tab_category_selector" /><RadioButtonandroid:id="@+id/home_tab_cart"style="@style/home_tab_bottom"android:background="@drawable/home_tab_background_selector"android:drawableTop="@drawable/home_tab_cart_selector" /><RadioButtonandroid:id="@+id/home_tab_personal"style="@style/home_tab_bottom"android:background="@drawable/home_tab_background_selector"android:drawableTop="@drawable/home_tab_personal_selector" /></RadioGroup></LinearLayout></TabHost>
以上是主要代码,完整文件可点击链接下载
/download/qq_45647961/19662896
如果觉得《【Android开发】网上商城》对你有帮助,请点赞、收藏,并留下你的观点哦!