08-19 Activity启动 全屏,横、竖屏 FrameLayout TableLayout Intent Extra传递数据
来源:互联网 发布:搭建网络视频直播 编辑:程序博客网 时间:2024/05/21 11:33
Activity启动
//****直接启动****@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); intent=getIntent(); textView= (TextView) findViewById(R.id.textView); textView.setText(intent.getStringExtra(Config.INTENT_TO)); Button btn=(Button)findViewById(R.id.button); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { intent=new Intent(MainActivity.this,Second_Activity.class); startActivityForResult(intent); } }); }//****带有返回值的启动**** Activity跳转 //**MainActivity**public class MainActivity extends Activity { private TextView textView; private Intent intent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); intent=getIntent(); textView= (TextView) findViewById(R.id.textView); textView.setText(intent.getStringExtra(Config.INTENT_TO)); Button btn=(Button)findViewById(R.id.button); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { intent=new Intent(MainActivity.this,Second_Activity.class); startActivityForResult(intent,12); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(resultCode==RESULT_OK){ String s=data.getStringExtra("sss"); textView.setText(s); } } @Override protected void onStart() { super.onStart(); Log.d("myApplication", "onStart "); } @Override protected void onRestart() { super.onRestart(); Log.d("myApplication", "onRestart"); } @Override protected void onResume() { super.onResume(); Log.d("myApplication", "onResume "); } @Override protected void onPause() { super.onPause(); Log.d("myApplication", "onPause "); } @Override protected void onStop() { super.onStop(); Log.d("myApplication", "onStop "); } @Override protected void onDestroy() { super.onDestroy(); Log.d("myApplication", "onDestroy "); }}//**activity_main.xml**<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <TextView android:text="@string/hello_world" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="启动第二个界面" android:id="@+id/button" android:layout_margin="@dimen/activity_horizontal_margin" /></RelativeLayout>![这里写图片描述](http://img.blog.csdn.net/20150819195712603)//**Second_Activity**public class Second_Activity extends Activity{ private EditText editText; private Button button; private Intent intent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_second); editText= (EditText) findViewById(R.id.editText);// intent=getIntent(); button= (Button) findViewById(R.id.button_back); button.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { Intent intent=new Intent(); intent.putExtra("sss",editText.getText().toString()); setResult(RESULT_OK,intent); Second_Activity.this.finish(); } }); Log.d("second_activity", "onCreate "); } @Override protected void onStart() { super.onStart(); Log.d("second_activity", "onStart "); } @Override protected void onResume() { super.onResume(); Log.d("second_activity", "onResume "); } @Override protected void onPause() { super.onPause(); Log.d("second_activity", "onPause "); } @Override protected void onStop() { super.onStop(); Log.d("second_activity", "onStop "); } @Override protected void onDestroy() { super.onDestroy(); Log.d("second_activity", "onDestroy "); }}//**activity_second**<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:weightSum="1"> <TextView android:text="第二个界面" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView" /> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/editText"/> <Button android:layout_width="100dp" android:layout_height="50dp" android:text="返回结果" android:id="@+id/button_back"/></LinearLayout>![这里写图片描述](http://img.blog.csdn.net/20150819200001443)
全屏、非全屏,横屏、竖屏
//******全屏、非全屏****** //**MainActivity** @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏 this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息栏 setContentView(R.layout.activity_main); intent=getIntent(); textView= (TextView) findViewById(R.id.textView); textView.setText(intent.getStringExtra(Config.INTENT_TO)); Button btn=(Button)findViewById(R.id.button); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { intent=new Intent(MainActivity.this,Second_Activity.class); startActivityForResult(intent,12); } }); }//**AndroidManifest.xml**<activity android:name=".MainActivity" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar.Fullscreen">//全屏 <intent-filter> <action android:name="com.example.administrator.myappplication.MainActivity"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity> ![全屏](http://img.blog.csdn.net/20150819201216930)![非全屏](http://img.blog.csdn.net/20150819201334453)//******竖屏、横屏****** //**AndroidManifest.xml** <activity android:name=".MainActivity" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:screenOrientation="portrait"//竖屏 android:screenOrientation="landscape">//横屏 <intent-filter> <action android:name="com.example.administrator.myappplication.MainActivity"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity> ![横屏](http://img.blog.csdn.net/20150819202202580) ![竖屏](http://img.blog.csdn.net/20150819202355427)
FrameLayout的属性
<?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"> <Button android:layout_width="150dp" android:layout_height="150dp" android:background="#ff0000" android:visibility="visible" //可见 android:visibility="invisible"//不可见,但还占据位置 android:visibility="gone"/> //相当于消除这个按钮 <Button android:layout_width="100dp" android:layout_height="100dp" /></FrameLayout>![visible](http://img.blog.csdn.net/20150819202810153)![invisible](http://img.blog.csdn.net/20150819202902473)![gone](http://img.blog.csdn.net/20150819202955374)
TableLayout的属性
/**android:stretchColumns 设置可伸展的列,自行沾满剩余空间android:shrinkColumns 设置可收缩的列,自行调整大小android:collapseColumns 设置要隐藏的列。**/<?xml version="1.0" encoding="utf-8"?><TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:stretchColumns="0,1,2" android:shrinkColumns="1"> <TableRow> <Button android:text="button1"/> <Button android:text="button2"/> <Button android:text="button3"/> </TableRow> <TableRow> <Button android:text="button1"/> <Button android:text="button2222222222222222222"/> <Button android:text="button3"/> </TableRow> <TableRow> <Button android:text="button1"/> <Button android:text="button2"/> <Button android:text="button3"/> </TableRow></TableLayout>![这里写图片描述](http://img.blog.csdn.net/20150819204330132)
Intent
//**ActionActivity**public class ActionActivity extends Activity{ private Button mButtonDIAL; private Button mButtonCALL; private Button mBtnWEB; private Button mBtnSMS; private Button mBtnDIAO; private EditText editText; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.action); //打电话 需要在AndroidManifest中添加权限 /* <uses-permission android:name="android.permission.CALL_PHONE"></uses-permission> */ mButtonDIAL= (Button) findViewById(R.id.button_DIAL); mButtonDIAL.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(); intent.setAction(Intent.ACTION_DIAL); intent.setData(Uri.parse("tel:18093193992")); startActivity(intent); } }); //直接打电话 mButtonCALL= (Button) findViewById(R.id.button_CALL); mButtonCALL.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(); intent.setAction(Intent.ACTION_CALL); intent.setData(Uri.parse("tel:18093193992")); startActivity(intent); } }); //发短信 mBtnSMS= (Button) findViewById(R.id.button_SMS); mBtnSMS.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(Intent.ACTION_SENDTO); intent.setData(Uri.parse("smsto;")); intent.putExtra("sms_body","The SMS Text"); startActivity(intent); } }); //打开网页 mBtnWEB= (Button) findViewById(R.id.button_WEB); mBtnWEB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://www.baidu.com")); startActivity(intent); } }); //隐式调用 mBtnDIAO= (Button) findViewById(R.id.button_diao); editText= (EditText) findViewById(R.id.edittext); mBtnDIAO.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent("com.example.administrator.myappplication.MainActivity"); String value=editText.getText().toString(); intent.putExtra(Config.INTENT_TO,value); startActivity(intent); } }); }}//**action_layout**<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/edittext"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="打电话" android:id="@+id/button_DIAL" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="直接打电话" android:id="@+id/button_CALL" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="发短信" android:id="@+id/button_SMS"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="打开网页" android:id="@+id/button_WEB"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="隐式启动" android:id="@+id/button_diao"/></LinearLayout>//**AndroidManifest**<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.example.administrator.myapplication" ><uses-permission android:name="android.permission.CALL_PHONE"></uses-permission><application android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:screenOrientation="portrait"> //隐式调用,跳转到哪个页面,intent-filter写在哪个页面 <intent-filter> <action android:name="com.example.administrator.myappplication.MainActivity"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity> <activity android:name=".Second_Activity"> </activity> <activity android:name=".ActionActivity"> </activity></application></manifest>![这里写图片描述](http://img.blog.csdn.net/20150819205317393)
Extra传递数据
//**发出信息的页面**public class Second_Activity extends Activity{ private EditText editText; private Button button; private Intent intent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_second); //设置editText 发送消息的输入框 editText= (EditText) findViewById(R.id.editText);// intent=getIntent(); button= (Button) findViewById(R.id.button_back); button.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { Intent intent=new Intent();//封装消息 intent.putExtra("sss",editText.getText().toString()); setResult(RESULT_OK,intent); Second_Activity.this.finish(); } }); Log.d("second_activity", "onCreate "); } @Override protected void onStart() { super.onStart(); Log.d("second_activity", "onStart "); } @Override protected void onResume() { super.onResume(); Log.d("second_activity", "onResume "); } @Override protected void onPause() { super.onPause(); Log.d("second_activity", "onPause "); } @Override protected void onStop() { super.onStop(); Log.d("second_activity", "onStop "); } @Override protected void onDestroy() { super.onDestroy(); Log.d("second_activity", "onDestroy "); }}//**得到信息的页面**public class MainActivity extends Activity { private TextView textView; private Intent intent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏 this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息栏 setContentView(R.layout.activity_main); intent=getIntent(); textView= (TextView) findViewById(R.id.textView);//****getStringExtra 获取信息**** textView.setText(intent.getStringExtra(Config.INTENT_TO)); Button btn=(Button)findViewById(R.id.button); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { intent=new Intent(MainActivity.this,Second_Activity.class); startActivityForResult(intent,12); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(resultCode==RESULT_OK){ String s=data.getStringExtra("sss"); textView.setText(s); } } @Override protected void onStart() { super.onStart(); Log.d("myApplication", "onStart "); } @Override protected void onRestart() { super.onRestart(); Log.d("myApplication", "onRestart"); } @Override protected void onResume() { super.onResume(); Log.d("myApplication", "onResume "); } @Override protected void onPause() { super.onPause(); Log.d("myApplication", "onPause "); } @Override protected void onStop() { super.onStop(); Log.d("myApplication", "onStop "); } @Override protected void onDestroy() { super.onDestroy(); Log.d("myApplication", "onDestroy "); }}//静态常量public class Config { public static final String INTENT_TO="qwe123asd";}
0 0
- 08-19 Activity启动 全屏,横、竖屏 FrameLayout TableLayout Intent Extra传递数据
- 08-19 Activity启动 全屏,横、竖屏 FrameLayout TableLayout Intent Extra传递数据
- 【intent extra】Android Activity直接传递数据
- Activity之间传递数据 Intent extra (p86-88)
- 使用Intent启动Activity传递数据
- 【Android】Intent中使用Extra传递数据
- Intent启动活动以及Intent传递数据&activity的生命周期
- 用Intent启动Activity,并在Activity之间传递数据
- 使用 Intent 启动 Activity和Activity之间的数据传递
- Intent的用法(一),启动activity传递数据以及startActivityForResult
- Intent的用法(一),启动activity传递数据以及startActivityForResult .
- Activity详解数据传递以及隐式Intent启动
- Intent传递数据与Activity启动模式singleTask的关系。
- Intent之使用Extra属性在组件之间传递数据
- activity开启一个启动模式为SingleTask的activity,intent传递数据为空的解决方法
- Activity启动模式及Intent传递对象
- Activity启动模式、Intent重复传递
- FrameLayout &TableLayout
- HEXO+Github,搭建自己的博客,最新版HEXO配置
- iOS开发系列--地图与定位
- 初识SVN
- CentOS学习3_CentOS6.5下安装Eclipse
- “调试器的协议与调试对象不兼容”错误的解决
- 08-19 Activity启动 全屏,横、竖屏 FrameLayout TableLayout Intent Extra传递数据
- Gradle学习目录总结
- 大三的大学总结 自省是为了不偏离轨道
- Emacs 学习(三)
- 浅谈IOC--说清楚IOC是什么
- 08-21 RadioGroup,RadioButton autoLink属性 TextView中ellipsize属性 TextView的属性
- 常见编码格式
- PHP中isset、empty、is_null实验测试
- Android中Toast的使用