码迷,mamicode.com
首页 > 移动开发 > 详细

Android-1

时间:2016-07-19 20:39:07      阅读:823      评论:0      收藏:0      [点我收藏+]

标签:

@String 支持多语言

layout中的text文本中String都尽量定义在String.xml中,便于多语言管理。

<resources>
<string name="app_name">HelloWorld</string>
<string name="action_settings">Settings</string>
<string name="text1">hello,you are the best!</string>
<string name="btn1">Jump to Another Activity</string>
<string name="title_activity_another">AnotherActivity</string>
</resources>

跳转另一个actvity

①监控点击动作可以有两种方式:

    1> 在layout中设置Button onclick属性为方法名,在activity里编写方法
    2> 在activity里findViewbyID 找到Button控件 ,设置监听事件
 
如采取第一种方法,要注意:

note that, in order for the system to match this method to the method name given to android:onClick, the signature must be exactly as shown. Specifically, the method must:

  • Be public
  • Have a void return value
  • Have a View as the only parameter (this will be the View that was clicked)

android:onClick="send"

public void send(View view){

Intent intent = new Intent(this,AnotherActivity.class);
startActivity(intent);

}


跳转网页

public void sendToBrowser(View view){

startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.baidu.com")));
}


activity的生命周期&activity跳转时的生命周期

技术分享

 

通过在代码中activity每个生命周期中添加system.out,了解activity生命周期

 

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
System.out.println("A onCreate");
}

protected void onStart() {
super.onStart();
System.out.println("A onStart");
}

protected void onResume() {
super.onResume();
System.out.println("A onResume");
}


..
..
..


在两个activity跳转的过程中,上一个activity如果不可见,则先执行onPause(),再执行onStop()
如果该activity仍可见(比如下一个activity是dialogue,则只执行onPause(),关闭dialogue直接执行onResume())

将activity设为dialogue的方法,在manifest文件中修改:
<activity
android:name=".AnotherActivity"
android:label="@string/title_activity_another"
android:theme="@style/Base.Theme.AppCompat.Dialog">
</activity>



Android-1

标签:

原文地址:http://www.cnblogs.com/biang/p/5681292.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!