我正在研究Ionic/Cordova,我添加了这个,androidManifest.xml但这对我不起作用,应用程序仍然以两种方式显示
android:screenOrientation="portrait"
Run Code Online (Sandbox Code Playgroud)
如何仅将我的应用限制为纵向模式?我已经检查了android并且它不起作用
Vad*_*ens 304
如果要仅在所有设备上限制为纵向模式,则应将此行添加到项目根文件夹中的config.xml.
<preference name="orientation" value="portrait" />
Run Code Online (Sandbox Code Playgroud)
之后,请在命令行中键入以下文本重建平台:
ionic build
Run Code Online (Sandbox Code Playgroud)
Tyl*_*ler 34
对于2和更高版本的离子,你还需要安装相应的离子本地包为你使用任何插件,包括cordova-plugin-和phonegap-plugin-插件.
安装Ionic Native Plugin
从CLI为插件安装Ionic Native的TypeScript模块.
$ ionic cordova plugin add --save cordova-plugin-screen-orientation
$ npm install --save @ionic-native/screen-orientation
Run Code Online (Sandbox Code Playgroud)
*请注意,该--save命令是可选的,如果您不希望将插件添加到package.json文件中,则可以省略该命令
导入ScreenOrientation插件
将插件导入到文档中controller提供的更多详细信息中.
import { ScreenOrientation } from '@ionic-native/screen-orientation';
@Component({
templateUrl: 'app.html',
providers: [
ScreenOrientation
]
})
constructor(private screenOrientation: ScreenOrientation) {
// Your code here...
}
Run Code Online (Sandbox Code Playgroud)做你的事
以编程方式锁定和解锁屏幕方向.
// Set orientation to portrait
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT);
// Disable orientation lock
this.screenOrientation.unlock();
Run Code Online (Sandbox Code Playgroud)奖励积分
您还可以获得当前的方向.
// Get current orientation
console.log(this.screenOrientation.type); // Will return landscape" or "portrait"
Run Code Online (Sandbox Code Playgroud)小智 11
根据https://cordova.apache.org/docs/en/4.0.0/config_ref/#global-preferences,
方向允许您锁定方向并防止界面响应方向的变化而旋转.可能的值包括默认值,横向或纵向.例:
<preference name="Orientation" value="landscape" />
请注意,这些值区分大小写,它是"方向",而不是"方向".
小智 6
如果你想在你的方向上做一些事情意味着你想在改变你的应用程序方向时执行任何操作,那么你必须使用离子框架插件...... https://ionicframework.com/docs/native/screen-orientation/
如果您只想将应用程序限制为纵向或横向模式,那么您只需在 config.xml 中添加以下行
<preference name="orientation" value="portrait" />
OR
<preference name="orientation" value="landscape" />
Run Code Online (Sandbox Code Playgroud)
android:screenOrientation="portrait"请在文件中添加androidManifest.xml为 android 活动标记的属性。
<activity
android:name="com.example.demo_spinner.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
</activity>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
76630 次 |
| 最近记录: |