应用程序启用方向更改按钮是状态栏 [英] Application enables orientation change button is status bar

查看:68
本文介绍了应用程序启用方向更改按钮是状态栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用nativescript,而且我总是在Galaxy Alpha的状态栏菜单上禁用切换器,以允许更改方向.当我打开我的应用程序时,按钮状态设置为启用.如何删除这种行为?

I use nativescript in my project, also I always disable toggler on status bar menu on my Galaxy Alpha that allows orientation change. When I open my app the button status is set to enabled. How to remove this behaviour?

这里是按钮含义的示例,在此屏幕上称为自动旋转. https://lh4.ggpht.com/LuZ3y6wD4aUBdBvZ8Wxf73BpWdfbfNdxOVcHMuRVgRcyz-dl9rRNUwtpx-L9uPlgJdc=h900

Here is an example of what button i mean, on this screen it called auto rotation. https://lh4.ggpht.com/LuZ3y6wD4aUBdBvZ8Wxf73BpWdfbfNdxOVcHMuRVgRcyz-dl9rRNUwtpx-L9uPlgJdc=h900

这是我的清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="org.nativescript.AzoftDeviceTracking"
          android:versionCode="1"
          android:versionName="1.0">

    <supports-screens
            android:smallScreens="true"
            android:normalScreens="true"
            android:largeScreens="true"
            android:xlargeScreens="true"/>

    <uses-sdk
            android:minSdkVersion="17"
            android:targetSdkVersion="25"/>

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <application
            android:name="com.tns.NativeScriptApplication"
            android:allowBackup="true"
            android:icon="@drawable/icon"
            android:label="@string/app_name"
            android:theme="@style/AppTheme">

        <activity
                android:name="com.tns.NativeScriptActivity"
                android:label="@string/title_activity_kimera"
                android:configChanges="keyboardHidden|screenSize"
                android:theme="@style/LaunchScreenTheme"
                android:screenOrientation="portrait">

            <meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme"/>

            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name="com.tns.ErrorReportActivity"/>
    </application>
</manifest>

更新 好的,我发现了原因,但在本机脚本代码中找不到它.

UPDATE Ok, I found possible reason but can't find it in nativescript code.

推荐答案

我遇到了同样的问题.最后,我使用了OrientationListener来检测用户何时将手机实际倾斜到横向,然后将方向设置为SCREEN_ORIENTATION_SENSOR.

I had the excact same problem. What I ended up with was using an OrientationListener to detect when the user had actually tilted the phone to landscape and then setting the orientation to SCREEN_ORIENTATION_SENSOR.

OrientationEventListener orientationEventListener = new OrientationEventListener(getActivity()) {
@Override
public void onOrientationChanged(int orientation) {
    int epsilon = 10;
    int leftLandscape = 90;
    int rightLandscape = 270;
    if(epsilonCheck(orientation, leftLandscape, epsilon) ||
       epsilonCheck(orientation, rightLandscape, epsilon)){
            getMainActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
        }
    }

    private boolean epsilonCheck(int a, int b, int epsilon) {
        return a > b - epsilon && a < b + epsilon;
    }
};
orientationEventListener.enable();

您还需要添加肖像检查,因为您在原始帖子中描述了需要.

You would also need to add checks for portrait , because you described needing that in your original post.

这篇关于应用程序启用方向更改按钮是状态栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆