zoukankan
html css js c++ java
Android中简单活动窗口的切换--Android
本例实现Android中简单Activity窗口切换:借助intent(意图)对应用操作(这里用按钮监听)等的描述,Android根据描述负责找对应的组件,完成组件的调用来实现活动的切换……案例比较简单直接附上代码了哈。
1、建两个Activity类,分别为MainActivity.java和GuideActivity.java……
MainActivity.java
(核心文件):
package livetelecast.thonlon.example.cn.thonlonlivetelecast;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity
extends AppCompatActivity {
private Button
btn_oprnActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.
activity_main);
btn_oprnActivity=(Button) findViewById(R.id.
btn_openActivity);
btn_oprnActivity.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=
new Intent();
intent.setClass(MainActivity.
this,GuidActivity.
class);
startActivity(intent);
}
});
}
}
GuideActivity.java:
package livetelecast.thonlon.example.cn.thonlonlivetelecast;
import android.app.Activity;
import android.os.Bundle;
/**
* Created by NIUXINLONG on 2018/4/29.
*/
public class GuidActivity
extends Activity{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.
activity_guide);
}
}
2、分别建立与Activity对应的布局文件activity_main.xml、activity_guide.xml:
activity_main.xml:
<?
xml version=
"1.0"
encoding=
"utf-8"?>
<
RelativeLayout
xmlns:
android
=
"http://schemas.android.com/apk/res/android"
android
:layout_width=
"match_parent"
android
:layout_height=
"match_parent">
<
Button
android
:id=
"@+id/btn_openActivity"
android
:layout_width=
"match_parent"
android
:layout_height=
"wrap_content"
android
:text=
"@string/btn_open"/>
</
RelativeLayout>
activity_guide.xml:
<?
xml version=
"1.0"
encoding=
"utf-8"?>
<
FrameLayout
xmlns:
android
=
"http://schemas.android.com/apk/res/android"
android
:layout_width=
"match_parent"
android
:layout_height=
"match_parent">
<
android.support.v4.view.ViewPager
android
:layout_width=
"match_parent"
android
:
layout_height
=
"match_parent">
</
android.support.v4.view.ViewPager>
<
LinearLayout
android
:layout_width=
"wrap_content"
android
:layout_height=
"wrap_content"
android
:layout_gravity=
"bottom|center_horizontal">
<
ImageView
android
:layout_width=
"wrap_content"
android
:layout_height=
"wrap_content"
android
:src=
"@drawable/point_select"
android
:padding=
"15dp"/>
<
ImageView
android
:layout_width=
"wrap_content"
android
:layout_height=
"wrap_content"
android
:src=
"@drawable/point_normal"
android
:padding=
"15dp"/>
</
LinearLayout>
</
FrameLayout>
3、配AndroidMenifest.xml:(重点是添加两activity)
<?
xml version=
"1.0"
encoding=
"utf-8"?>
<
manifest
xmlns:
android
=
"http://schemas.android.com/apk/res/android"
package=
"livetelecast.thonlon.example.cn.thonlonlivetelecast">
<
application
android
:allowBackup=
"false"
android
:icon=
"@mipmap/ic_launcher"
android
:label=
"@string/app_name"
android
:roundIcon=
"@mipmap/ic_launcher_round"
android
:supportsRtl=
"true"
android
:theme=
"@style/AppTheme">
<
activity
android
:name=
".MainActivity">
<
intent-filter>
<
action
android
:name=
"android.intent.action.MAIN" />
<
category
android
:name=
"android.intent.category.LAUNCHER" />
</
intent-filter>
</
activity>
<
activity
android
:name=
".GuidActivity"/>
</
application>
</
manifest>
查看全文
相关阅读:
串口调试助手的源码分析,子对话框部分
vc 使用了SerialPort类的串口通信软件分析
Web前端研发工程师编程能力飞升之路
vc mscomm串口通信使用了CButtonST按钮类软件分析
vc 串口精灵软件分析
c#串口完全接收程序
Windows Server 2003操作系统中禁用Internet Explorer增强的安全特性
Window下查看进程端口号
面向对象的设计原则(2)——依赖注入
面向对象的设计原则(1)
原文地址:https://www.cnblogs.com/qikeyishu/p/8972483.html
最新文章
01-13 打电话
01-12 图片无损拉伸
01-12 IOS获取手机与屏幕属性
01-12 自定义tabbar (转)
01-11 常用view位置转换
01-11 引导页(2)= 文顶顶
01-11 单例模式
01-09 引导页(代码 1 )
01-09 通知
0108 --block -__weak self
热门文章
MySQL5 LOAD DATA 的使用
mysql出现mysql server has gone away错误的解决办法
web 压力测试工具ab压力测试详解
使用PHP导入和导出CSV文件
ecmall中的分页问题
thinkphp3.0中ajax的发送
BinaryReader 、BinaryWriter是方便用二进制方式读写int,double,string之类的数据
如何将编辑框控件"滚动条"一直保持往下滚
MFC串口的编程 mscomm控件与SerialPort类
CserialPort类的简单用法
Copyright © 2011-2022 走看看