第三天 --->商城项目的开始
从今天开始,做一个商城项目:
今天晚上我们实现的功能是:
FragmentTabHost +selector实现底部菜单,
FragemntTabHost:
要求我们的class必须继承FragmentActivity,
mInflater = LayoutInflater.from(this);
mTabHost =(FragmentTabHost) this.findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);*/
//mTabHost.addTab(mTabHost.newTabSpec("home").setIndicator());
TabHost.TabSpec tabSpec= mTabHost.newTabSpec("home");
//存放我们的菜单选项布局
View view = mInflater.inflate(R.layout.tab_indicator, null);
ImageView img= (ImageView)view.findViewById(R.id.icon_tab);
TextView text = (TextView)view.findViewById(R.id.txt_indicator);
img.setBackgroundResource(R.mipmap.icon_home);
text.setText("主页");
tabSpec.setIndicator(view);
mTabHost.addTab(tabSpec, HomeFargment.class, null);
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="demo.mrlong.com.cainiaodemo.MainActivity">
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:background="@color/bg_color"
/>
<android.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
</android.support.v4.app.FragmentTabHost>
</LinearLayout>

浙公网安备 33010602011771号