有關phonegap 應用在android平台全屏

來源:互聯網
上載者:User

問題: 利用phonegap 打包android 程式 在裝置上全螢幕顯示;

 

我們有時需要把 Activity 設定成全螢幕顯示,一般情況下,可以通過兩種方式來設定全螢幕顯示效果。

一,通過在代碼中可以設定,

代碼中設定(如下)

public void onCreate(Bundle savedInstanceState) {          super.onCreate(savedInstanceState);                    //設定無標題          requestWindowFeature(Window.FEATURE_NO_TITLE);          //設定全屏          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,                   WindowManager.LayoutParams.FLAG_FULLSCREEN);                    setContentView(R.layout.main);  }  

       但要注意的是:在代碼中設定的話,設定無標題和設定全屏的兩段代碼要放置在 setContentView(R.layout.main); 這段代碼的前面。要不然會報錯。

       其二:在manifest設定檔中設定

代碼如下:

<?xml version="1.0" encoding="utf-8"?>  <manifest xmlns:android="http://schemas.android.com/apk/res/android"        package="com.andyidea"        android:versionCode="1"        android:versionName="1.0">      <uses-sdk android:minSdkVersion="8" />      <application android:icon="@drawable/icon" 
          android:label="@string/app_name"          android:theme="@android:style/android.NoTitleBar.Fullscreen"> <activity android:name=".login.LoginActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>

這個樣設定解決不了問題。發現用phonegap打包出來任然不是全屏

在方法一種添加一行代碼

    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);// 清除FLAG 這行是重點        requestWindowFeature(Window.FEATURE_NO_TITLE);        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

完整的代碼:

phonegap 打包完成代碼

public class SaleActivity extends DroidGap {    private static final String TARGET_URL = "http:";         private Context context = this;    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setFullscreen();        if (checkNetwork()) {            super.init();            super.appView.clearCache(true);            super.setBooleanProperty("loadInWebView", true);            super.setIntegerProperty("loadUrlTimeoutValue", 10000); // 載入時間            super.setIntegerProperty("splashscreen", R.drawable.splash);// 引導頁            super.loadUrl(TARGET_URL, 8000); // 設定頁面            super.setBooleanProperty("keepRunning", true); // 保持在後台運行        } else {            showDialog();        }    }    // 檢查網路狀態    private boolean checkNetwork() {        ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);        NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();        if (networkInfo != null && networkInfo.isConnected()                && networkInfo.isAvailable()) {            return true;        } else {            return false;        }    }    // 彈出對話方塊    protected void showDialog() {        AlertDialog.Builder builder = new Builder(context);        builder.setMessage("當前未串連網路,是否設定?");        builder.setTitle("提示");        builder.setPositiveButton("確認", new OnClickListener() {            @Override            public void onClick(DialogInterface dialog, int which) {                SaleActivity.this.finish();                Intent intent = new Intent("android.settings.WIRELESS_SETTINGS");                startActivity(intent);            }        });        builder.setNegativeButton("取消", new OnClickListener() {            @Override            public void onClick(DialogInterface dialog, int which) {                SaleActivity.this.finish();            }        });        builder.create().show();    }    // 全屏(無標題列和狀態列)    protected void setFullscreen() {        getWindow().clearFlags(                WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);// 清除FLAG        requestWindowFeature(Window.FEATURE_NO_TITLE);        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,                WindowManager.LayoutParams.FLAG_FULLSCREEN);    }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.