Activity1如下:
package cn.com; import android.app.Activity; import android.os.Bundle; public class Activity1 extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //设置setTitle应该在setTitle之前 //否则不起作用 setTitle("Activity1"); setContentView(R.layout.activity_1); } }
Activity2如下:
package cn.com; import android.app.Activity; import android.os.Bundle; public class Activity2 extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //设置setTitle应该在setTitle之前 //否则不起作用 setTitle("Activity2"); setContentView(R.layout.activity_2); } }
Activity3如下:
package cn.com; import android.app.Activity; import android.os.Bundle; public class Activity3 extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //设置setTitle应该在setTitle之前 //否则不起作用 setTitle("Activity3"); setContentView(R.layout.activity_3); } }
Activity4如下:
package cn.com; import android.app.Activity; import android.os.Bundle; public class Activity4 extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //设置setTitle应该在setTitle之前 //否则不起作用 setTitle("Activity4"); setContentView(R.layout.activity_4); } }
BottomMenuView如下:
package cn.com; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; //自定义View.仿TabHost的实现 public class BottomMenuView extends LinearLayout{ private Context mContext; private LinearLayout mLinearLayout1; private LinearLayout mLinearLayout2; private LinearLayout mLinearLayout3; private LinearLayout mLinearLayout4; private String mCurrentActivityTitle; private final static String ACTIVITY_NAME_1="Activity1"; private final static String ACTIVITY_NAME_2="Activity2"; private final static String ACTIVITY_NAME_3="Activity3"; private final static String ACTIVITY_NAME_4="Activity4"; public BottomMenuView(Context context, AttributeSet attrs) { super(context, attrs); mContext=context; initView(); } private void initView(){ View bottomMenuView= LayoutInflater.from(mContext).inflate(R.layout.bottommenu, null, false); ViewGroup.LayoutParams params= new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); this.addView(bottomMenuView,params); mLinearLayout1=(LinearLayout) bottomMenuView.findViewById(R.id.menu_LinearLayout1); mLinearLayout2=(LinearLayout) bottomMenuView.findViewById(R.id.menu_LinearLayout2); mLinearLayout3=(LinearLayout) bottomMenuView.findViewById(R.id.menu_LinearLayout3); mLinearLayout4=(LinearLayout) bottomMenuView.findViewById(R.id.menu_LinearLayout4); BottomMenuOnClickListener clickListener=new BottomMenuOnClickListener(); mLinearLayout1.setOnClickListener(clickListener); mLinearLayout2.setOnClickListener(clickListener); mLinearLayout3.setOnClickListener(clickListener); mLinearLayout4.setOnClickListener(clickListener); setEveryMenuStatus(); } /** * * 1 在每个menu对应的Activity中设置其Title * 2 在此判断当前显示是哪一个Activity.使得 * 当前Activity对应的Menu不可再次点击. */ private void setEveryMenuStatus(){ mCurrentActivityTitle=(String) ((Activity)mContext).getTitle(); if (mCurrentActivityTitle.equals(ACTIVITY_NAME_1)) { mLinearLayout1.setClickable(false); }else if (mCurrentActivityTitle.equals(ACTIVITY_NAME_2)) { mLinearLayout2.setClickable(false); }else if (mCurrentActivityTitle.equals(ACTIVITY_NAME_3)) { mLinearLayout3.setClickable(false); }else if (mCurrentActivityTitle.equals(ACTIVITY_NAME_4)) { mLinearLayout4.setClickable(false); } } private class BottomMenuOnClickListener implements OnClickListener{ public void onClick(View v) { switch (v.getId()) { case R.id.menu_LinearLayout1: Intent intent1=new Intent(mContext, Activity1.class); mContext.startActivity(intent1); break; case R.id.menu_LinearLayout2: Intent intent2=new Intent(mContext, Activity2.class); mContext.startActivity(intent2); break; case R.id.menu_LinearLayout3: Intent intent3=new Intent(mContext, Activity3.class); mContext.startActivity(intent3); break; case R.id.menu_LinearLayout4: Intent intent4=new Intent(mContext, Activity4.class); mContext.startActivity(intent4); break; default: break; } } } }