zoukankan      html  css  js  c++  java
  • android页面切换

    修改strings.xml

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    <string name="layout1">this is Layout 1</string>
    <string name="layout2">This is Layout 2</string>
    <string name="app_name">Ex8_UI</string>
    </resources>
    

    新建color.xml 保存两个颜色值 (放到res/values目录中)

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    <color name="black">#000000</color>
    <color name="white">#FFFFFFFF</color>
    </resources>
    

    修改main.xml 布局,添加一个TextView 和一个Button

    <?xml version="1.0" encoding="utf-8"?>
    <AbsoluteLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/black"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <TextView
    android:id="@+id/text1"
    android:textSize="24sp"
    android:layout_width="186px"
    android:layout_height="29px"
    android:layout_x="70px"
    android:layout_y="32px"
    android:text="@string/layout1"
    ></TextView>
    <Button
    android:id="@+id/button1"
    android:layout_width="118px"
    android:layout_height="wrap_content"
    android:layout_x="100px"
    android:layout_y="82px"
    android:text="Go to Layout2"
    ></Button>
    </AbsoluteLayout>
    
    


    新建mylayout.xml 布局文件(放到res/layout目录中),并添加两个View:TextView 和Button

    <?xml version="1.0" encoding="utf-8"?>
    <AbsoluteLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/white"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <TextView
    android:id="@+id/text2"
    android:textSize="24sp"
    android:layout_width="186px"
    android:layout_height="29px"
    android:layout_x="70px"
    android:layout_y="32px"
    android:textColor="@color/black"
    android:text="@string/layout2"
    > </TextView>
    <Button
    android:id="@+id/button2"
    android:layout_width="118px"
    android:layout_height="wrap_content"
    android:layout_x="100px"
    android:layout_y="82px"
    android:text="Go to Layout1"
    ></Button>
    </AbsoluteLayout>
    
    

    编写mainActivity.java

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package org.me.setcontentviewapp;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    
    /**
    *
    * @author LiaoKeCheng<http://hi.baidu.com/wishwingliao>
    */
    public class MainActivity extends Activity
    {
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate( Bundle icicle )
        {
            super.onCreate( icicle );
            /* 载入main.xml Layout */
            setContentView( R.layout.main );// 默认启动布局
            /* 以findViewById()取得Button 对象,并添加onClickListener */
            Button b1 = ( Button ) findViewById( R.id.button1 );
            b1.setOnClickListener( new Button.OnClickListener()
            {
    
                public void onClick( View v )
                {
                    jumpToLayout2();// 调用跳转方法jumpToLayout2()
                }
            } );
        }
    
        /**
         * method jumpToLayout2:将layout由 main.xml 切 换成mylayout.xml
         */
        public void jumpToLayout2()
        {
            /* 将layout 改成mylayout.xml */
            setContentView( R.layout.mylayout );
            /* 以findViewById()取得Button 对象,并添加onClickListener */
            Button b2 = ( Button ) findViewById( R.id.button2 );
            b2.setOnClickListener( new Button.OnClickListener()
            {
    
                public void onClick( View v )
                {
                    jumpToLayout1();// 调用跳转方法jumpToLayout1()
                }
            } );
        }
    
        /**
         * method jumpToLayout1:将layout 由mylayout.xml 切换成main.xml
         */
        public void jumpToLayout1()
        {
            /* 将layout 改成main.xml */
            setContentView( R.layout.main );
            /* 以findViewById()取得Button 对象,并添加onClickListener */
            Button b1 = ( Button ) findViewById( R.id.button1 );
            b1.setOnClickListener( new Button.OnClickListener()
            {
    
                public void onClick( View v )
                {
                    jumpToLayout2();// 调用跳转方法jumpToLayout2()
                }
            } );
        }
    }
    
  • 相关阅读:
    大数据第59天—MySQL之员工奖金-杨大伟
    大数据第58天—MySQL常用命令-杨大伟
    大数据第56天—Mysql练习题12道之十一-查出销售表中所有会员购买金额,同时分组查出退货表中所有会员的退货金额-杨大伟
    大数据第55天—Mysql练习题12道之十-查询各自区组的money排名前十的账号-杨大伟
    大数据第54天—Mysql练习题12道之九-充值日志表-杨大伟
    大数据第53天—Mysql练习题12道之八-线上服务器访问日志-杨大伟
    大数据第52天—Mysql练习题12道之七-图书管理数据库-杨大伟
    mac 破解pycharm2020.2.3
    mac连接oracle数据库
    python DPI-1047:Cannot locate a 64-bit Oracle Client library:The specified module could not be found.
  • 原文地址:https://www.cnblogs.com/lm3515/p/2000382.html
Copyright © 2011-2022 走看看