zoukankan      html  css  js  c++  java
  • Android-1

    @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>



  • 相关阅读:
    洛谷提高组比赛day2
    清北合肥day2-day5
    高精度开根
    清北合肥day1
    愤怒的小鸟
    蓝书图论题
    替罪羊树&&非旋treap
    【bzoj4811】[Ynoi2017]由乃的OJ 树链剖分+线段树区间合并
    【bzoj3866】The Romantic Hero dp
    【bzoj3747】[POI2015]Kinoman
  • 原文地址:https://www.cnblogs.com/biang/p/5681292.html
Copyright © 2011-2022 走看看