zoukankan      html  css  js  c++  java
  • activity横竖平切换处理

    简单的问题,没有什么好说的。分一下几步:

      1.首先在配置文件里声明某个activity来自己处理横竖屏切换和键盘的合入何处(摩托的手机就喜欢这样):

    <activity android:name=".MyActivity"
    android:configChanges="orientation|keyboardHidden"
    android:label="@string/app_name">

    注:如果你的sdk的api为13及以上,应该改为:

    android:configChanges="orientation|screenSize"

      2.然后重写Configuation方法来处理你声明的事件。类似如下:

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    // Checks the orientation of the screen
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
    Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
    Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
    }
    }

    注:1.默认的处理是杀死当前的activity,然后重新生成这个activity.

      2.super.onConfigurationChanged(newConfig)这段放心使用,不会重启当前的activity的。

      3.如果你的sdk的api为13及以上,应该改为:




  • 相关阅读:
    Github国内mirror加速
    通过node-inspector或VSCode调试服务器上代码
    node nvm 常见命令
    HBuilderX 修改默认的终端
    LLVM 工具使用
    LLVM 获取Value Type
    LLVM Constant Value to c++ value
    Bison 命名位置
    llvm block
    vscode use cl.exe build C/C++
  • 原文地址:https://www.cnblogs.com/slider/p/2298703.html
Copyright © 2011-2022 走看看