乐学成语——第二部分

来源:互联网 发布:unity3d打砖块 源代码 编辑:程序博客网 时间:2024/04/29 02:05

    1. (1)主页面的设计采用选项卡组件,在res的drawable-hdpi目录下拷入需要的图片素材,在res/layout目录中新建activity_main.xml布局。布局文件中的内容比较简单,主要是拖了一个TabHost控件到界面上。

<span style="font-family:KaiTi_GB2312;font-size:18px;"><TabHost         android:id="@android:id/tabhost"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:layout_alignParentLeft="true"        android:layout_alignParentTop="true">        <LinearLayout             android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="vertical"> </span>
<span style="font-family:KaiTi_GB2312;font-size:18px;"><pre class="html" name="code"> <TabWidget                 android:id="@android:id/tabs"                android:layout_width="match_parent"                android:layout_height="wrap_content">                         </TabWidget></span>
<span style="font-family:KaiTi_GB2312;font-size:18px;">           <FrameLayout             android:id="@android:id/tabcontent"            android:layout_width="match_parent"            android:layout_height="match_parent"            android:layout_weight="1">             <LinearLayout             android:id="@+id/tab1"            android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="vertical">            </LinearLayout>            <LinearLayout             android:id="@+id/tab2"            android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="vertical">            </LinearLayout>             <LinearLayout             android:id="@+id/tab3"            android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="vertical">            </LinearLayout>            </FrameLayout>  </span>

   2. (1)然后在res的values目录的strings.xml文件中定义所需要的字符串插入即可

<span style="font-family:KaiTi_GB2312;font-size:18px;"><span style="font-family:KaiTi_GB2312;font-size:18px;">    <string name="title_study">学习</string>    <string name="title_search">搜搜</string>    <string name="title_game">游戏</string>    <string name="title_save">收藏</string>    <string name="title_help">帮助</string></strong></span><span style="font-family:KaiTi_GB2312;font-size:18px;"> </span></span>

  (2)编写活动:在activity包下创建MainActivity继承自Activity。在这个类的onCreate()方法里,通过调用getTabHost()方法来获取整个TabHost组件,然后调用了抽取出来的自定义的方法addTab()添加了5个选项卡。方法的4个参数分别为每个选项卡的Tag,指示器上显示标题,显示图片,选项卡对应的内容。

    需要注意的是,取消标题栏的方法,一定要位于setContentView()方法之前。如下

<span style="font-family:KaiTi_GB2312;font-size:18px;"><span style="font-family:KaiTi_GB2312;font-size:18px;">       requestWindowFeature(Window.FEATURE_NO_TITLE);//取消标题栏       setContentView(R.layout.activity_main);</span></span>

    (3)在运行之前要先修改配置文件AndroidMainfest.xml中的代码,主要是注册了MainActivity,通过加入<intent-filter>将其设置为首先启动类。在编写过程中,要读懂他的含义,<intent-filter>为首先启动类,如果设置错,则会找不到启动类。 

<span style="font-family:KaiTi_GB2312;font-size:18px;"><span style="font-family:KaiTi_GB2312;font-size:18px;">        <activity            android:name="cn.edu.bztc.happyidiom.activity.MainActivity"            android:label="@string/title_activity_main">            <intent-filter>                            <action android:name="android.intent.action.MAIN" />                               <category android:name="android.intent.category.LAUNCHER" />             </intent-filter>        </activity></span></span>

  

    3.(1)其实在Android4.2上的,只有文字标题显示,图标是不显示的。可以通过修改主题来实现,插入第三行代码即可。

<span style="font-family:KaiTi_GB2312;font-size:18px;"><span style="font-family:KaiTi_GB2312;font-size:18px;"><activity            android:name="cn.edu.bztc.happyidiom.activity.MainActivity"            android:label="@string/title_activity_main"            android:theme="@android:style/Theme.NoTitleBar"></span></span>

     

      (2)如果想让指示器显示在底部,在activity_main.xml中FrameLayout添加

<span style="font-family:KaiTi_GB2312;font-size:18px;"><span style="font-family:KaiTi_GB2312;font-size:18px;">android:layout_weight="1"</span><pre class="html" name="code"><span style="font-family:KaiTi_GB2312;font-size:18px;"><TabWidget                 android:id="@android:id/tabs"                android:layout_width="match_parent"                android:layout_height="wrap_content">                         </TabWidget>      //置底</span></span>


           
    

 


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 八个月宝宝感冒流鼻涕鼻塞怎么办 7岁儿童流清鼻涕怎么办 1岁的宝宝流鼻涕怎么办 3岁宝宝鼻塞严重怎么办 宝宝流鼻涕2个月怎么办 一个月宝宝流鼻子怎么办 六个月宝宝流清水鼻涕怎么办 婴儿流鼻涕怎么办最简单方法 婴儿咳嗽流鼻涕怎么办最简单方法 6个月小孩流鼻涕怎么办 宝宝风寒感冒咳嗽流鼻涕怎么办 三个月宝宝流清鼻涕怎么办 三个月宝宝留清鼻涕怎么办 三个月婴儿流清鼻涕怎么办 宝宝7个月流鼻涕怎么办 6个月孩子流鼻涕怎么办 十一个月孩子感冒流鼻涕怎么办 7个月孩子流鼻涕怎么办 18个月的宝宝流鼻涕怎么办 6个月宝宝咳嗽流鼻涕怎么办 18个月宝宝咳嗽流鼻涕怎么办 6个月宝宝流鼻涕打喷嚏怎么办 宝宝18个月流鼻涕怎么办 18个月宝宝感冒流鼻涕怎么办 小孩睡觉鼻子不通气怎么办 宝宝鼻子里有鼻涕出不来怎么办 孩子喉咙有痰呼呼响怎么办 六个月宝宝鼻塞怎么办速效办法 两个月小孩鼻子不通气怎么办 一岁宝宝流清鼻涕怎么办 孩子鼻子里有鼻涕怎么办 宝宝晚上睡觉鼻子不通气怎么办 宝宝感冒睡觉鼻子不通气怎么办 宝宝3个月流鼻涕怎么办 小孩吃着了发烧怎么办 半岁宝宝鼻子塞怎么办 宝宝伤风鼻子不通气怎么办 二十天的宝宝伤风鼻子不通怎么办 一个多月的宝宝鼻子有鼻屎怎么办 2个月宝宝鼻子里有鼻屎怎么办 四个月婴儿感冒发烧怎么办