[英]How to set the application to fullscreen from an Intent, Not from the main activity
我的應用程序有4個選項卡,每個選項卡都會創建一個子視圖(意圖),現在我在每個意圖中都有一個用於選項/菜單按鈕的處理程序,菜單項為“切換全屏”,這不起作用,因為意圖不是父項視圖,而包含TabHost的活動是父視圖,現在我需要知道如何設置整個應用程序。 進入全屏模式,或如何參考父活動通過它設置全屏模式。
這是我的代碼片段
public class MainActivity extends TabActivity {
public void toggleFullScreen(){
// This has the code to set App. to full screen
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent myIntent = new Intent(this, MywebviewActivity.class);
tabHost.addTab(
tabHost.newTabSpec("SomeName")
.setIndicator("Some Title")
.setContent( myIntents ));
現在,我需要從“ MywebviewActivity”而不是從MainActivity設置全屏模式
檢查這個
將此添加到您的webview活動中
Intent i=getIntent();
if(i!=null)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
如下修改MainActivity
代碼
Intent myIntent = new Intent(this, MywebviewActivity.class);
intent.putExtra("isFullScreen", true);
現在在MywebviewActivity
onCreate()
方法中編寫代碼,如下所示
把“ setContentView(R.layout.main);” 此代碼下面的方法如下:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent=getIntent();
boolean isfullScreen = intent.getBooleanExtra("isFullScreen", false);
if(isfullScreen )
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
setContentView(R.layout.main);
}
不行
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.