在全屏模式下隐藏标题?

时间:2021-03-08 19:17:02

Is there a way to hide the window title so that it won't get shown in fullscreen mode (

有没有办法隐藏窗口标题,以便它不会以全屏模式显示(

getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN,
                LayoutParams.FLAG_FULLSCREEN)

) but then will appear upon

)但随后会出现

getWindow().clearFlags(LayoutParams.FLAG_FULLSCREEN)

?

requestWindowFeature(Window.FEATURE_NO_TITLE)

is not an option of course as this won't allow to get it back.

当然不是一个选择,因为这不会让它回来。

6 个解决方案

#1


57  

The way I handle this in my Android games is to call the following line in the onCreate() of my Activity

我在Android游戏中处理这个问题的方法是在我的Activity的onCreate()中调用以下行

requestWindowFeature(Window.FEATURE_NO_TITLE);

I can then turn the full screen capability off and on using the following code in my activity class (usually called from a menu option) (the m_contentView variable is the view from findViewById() using the id that you used when calling setContentView() in your on create)

然后,我可以在我的activity类中使用以下代码关闭全屏功能(通常从菜单选项调用)(m_contentView变量是来自findViewById()的视图,使用您在调用setContentView()时使用的id你的创造)

private void updateFullscreenStatus(boolean bUseFullscreen)
{   
   if(bUseFullscreen)
   {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    }
    else
    {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    m_contentView.requestLayout();
}

I use this technique in all of my games without problem.

我在所有游戏中都使用这种技术而没有任何问题。

Why do you say

为什么这么说

requestWindowFeature(Window.FEATURE_NO_TITLE); is not an option of course

requestWindowFeature(Window.FEATURE_NO_TITLE);当然不是一个选择

?

::EDIT::

Well if you are trying to dynamically show and hide it during the lifetime of the activity I am not sure if you can do that with the official Window Title due to the note that has been mentioned about window features needing to be set before setContentView() is called (link)

好吧,如果你想在活动的生命周期中动态显示和隐藏它,我不确定你是否可以使用正式的窗口标题来做到这一点,因为已经提到过关于需要在setContentView()之前设置的窗口特征的注释叫(链接)

One thing that you could do is implement your own title bar and dynamically show and hide that... I put together this example that should set you o nthe right track

你可以做的一件事是实现你自己的标题栏并动态显示和隐藏...我把这个例子放在一起,应该让你在正确的轨道上

Here is the layout file

这是布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:fadingEdgeLength="0sp"
    >

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/myTitleBarLayout" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >

        <TextView
            android:id="@+id/myTitleBarTextView"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:text="@string/app_name"
            android:paddingTop="4dip"
            android:paddingBottom="4dip"
            android:paddingLeft="6dip"
            android:textStyle="bold"
            android:shadowColor="#BB000000"
            android:shadowRadius="3.0"
            android:shadowDy=".25"

        />

        <View
            android:layout_width="fill_parent"
            android:layout_height="1dip"
            android:background="#CCEEEEEE"
            android:padding="10dip"
        />
    </LinearLayout>

    <ScrollView  xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:layout_weight="1"
        >

        <!-- Insert your regular layout stuff here -->

        <Button android:id="@+id/toggle_title_button" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:text="Toggle Title" 
        />
    </ScrollView>
</LinearLayout>

And here is the code for the main activity that will allow you to toggle our custom title bar on and off

这里是主要活动的代码,允许您打开和关闭我们的自定义标题栏

package com.snctln.test.HelloGridView;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class HelloGridView extends Activity
{
    public void onCreate(Bundle savedInstanceState)
    {
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TextView tv = (TextView)this.findViewById(R.id.myTitleBarTextView);
        tv.setBackgroundColor(0xFF848284);
        tv.setTextColor(0xFFFFFFFF);

        Button toggleTitleButton = (Button)this.findViewById(R.id.toggle_title_button);

        toggleTitleButton.setOnClickListener( new OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    LinearLayout ll = (LinearLayout)findViewById(R.id.myTitleBarLayout);

                    if(ll.getVisibility() == View.GONE)
                    {
                        ll.setVisibility(View.VISIBLE);
                    }
                    else
                    {
                        ll.setVisibility(View.GONE);
                    }
                }
            });
    }
}

It doesn't look perfect, but you can always play with the layout some more to do that.

它看起来并不完美,但你可以随时使用布局来做到这一点。

alt text http://i39.tinypic.com/120sfp1.png

替代文字http://i39.tinypic.com/120sfp1.png

My other thought is if you just want to hide everything to show a progress bar why not use the ProgressDialog?

我的另一个想法是,如果你只想隐藏所有内容以显示进度条,为什么不使用ProgressDialog?

This class is pretty easy to use...

这个类很容易使用......

progressDlg = ProgressDialog.show(context, getString(R.string.progress_dialog_title_prepare), getString(R.string.progress_dialog_body_prepare));

// do long running operation

if(operationFailed)
{
    progressDlg.cancel();
}
else
{
    progressDlg.dismiss();
}

#2


13  

Adding android:theme="@android:style/Theme.NoTitleBar.Fullscreen" to application tag in the manifest file will make every activity fullscreen.

将android:theme =“@ android:style / Theme.NoTitleBar.Fullscreen”添加到清单文件中的应用程序标记将使每个活动全屏显示。

#3


11  

To disable the title of your application (it is the app name)

禁用应用程序的标题(它是应用程序名称)

requestWindowFeature(Window.FEATURE_NO_TITLE)

To disable the notification bar on the top (so a request to the android app manager to allow Fullscreen)

要禁用顶部的通知栏(因此请求Android应用程序管理器允许全屏)

getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN)

Hope this helps any one who wants to know the difference!!

希望这能帮助任何想要了解差异的人!

#4


10  

if(useFullscreen)  
{  
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);  
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);  
}  
else  
{  
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);  
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);  
}  

this worked for me .. at onResume method

这对我有用..在onResume方法

#5


3  

On Android 3+ it can be easilyy achieved by calling getActionBar().hide() and getActionBar().show() to respectively show and hide the standard ActionBar

在Android 3+上,可以通过调用getActionBar()。hide()和getActionBar()。show()分别显示和隐藏标准ActionBar来轻松实现。

On Android 1,2 the best solution (I guess) is to implement custom View for yout "title bar" and hide it on demand (of course, calling to requestWindowFeature(Window.FEATURE_NO_TITLE); at the beginning).

在Android 1,2上,最好的解决方案(我猜)是为你的“标题栏”实现自定义View并按需隐藏它(当然,调用requestWindowFeature(Window.FEATURE_NO_TITLE);在开头)。

#6


1  

that is not possible according to the docs and the android-developers google group. to implement that , you need to add a 'title-bar-like' layout item with your text and progress bar and hide/show when you need it. right now - no other way around it, since title bar control can be done only before the setContentView call and not changed after.

根据文档和Android开发人员谷歌组不可能。要实现这一点,您需要在文本和进度条中添加“标题栏”布局项,并在需要时隐藏/显示。现在 - 没有其他方法,因为标题栏控件只能在setContentView调用之前完成,之后不会更改。

#1


57  

The way I handle this in my Android games is to call the following line in the onCreate() of my Activity

我在Android游戏中处理这个问题的方法是在我的Activity的onCreate()中调用以下行

requestWindowFeature(Window.FEATURE_NO_TITLE);

I can then turn the full screen capability off and on using the following code in my activity class (usually called from a menu option) (the m_contentView variable is the view from findViewById() using the id that you used when calling setContentView() in your on create)

然后,我可以在我的activity类中使用以下代码关闭全屏功能(通常从菜单选项调用)(m_contentView变量是来自findViewById()的视图,使用您在调用setContentView()时使用的id你的创造)

private void updateFullscreenStatus(boolean bUseFullscreen)
{   
   if(bUseFullscreen)
   {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    }
    else
    {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    m_contentView.requestLayout();
}

I use this technique in all of my games without problem.

我在所有游戏中都使用这种技术而没有任何问题。

Why do you say

为什么这么说

requestWindowFeature(Window.FEATURE_NO_TITLE); is not an option of course

requestWindowFeature(Window.FEATURE_NO_TITLE);当然不是一个选择

?

::EDIT::

Well if you are trying to dynamically show and hide it during the lifetime of the activity I am not sure if you can do that with the official Window Title due to the note that has been mentioned about window features needing to be set before setContentView() is called (link)

好吧,如果你想在活动的生命周期中动态显示和隐藏它,我不确定你是否可以使用正式的窗口标题来做到这一点,因为已经提到过关于需要在setContentView()之前设置的窗口特征的注释叫(链接)

One thing that you could do is implement your own title bar and dynamically show and hide that... I put together this example that should set you o nthe right track

你可以做的一件事是实现你自己的标题栏并动态显示和隐藏...我把这个例子放在一起,应该让你在正确的轨道上

Here is the layout file

这是布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:fadingEdgeLength="0sp"
    >

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/myTitleBarLayout" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >

        <TextView
            android:id="@+id/myTitleBarTextView"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:text="@string/app_name"
            android:paddingTop="4dip"
            android:paddingBottom="4dip"
            android:paddingLeft="6dip"
            android:textStyle="bold"
            android:shadowColor="#BB000000"
            android:shadowRadius="3.0"
            android:shadowDy=".25"

        />

        <View
            android:layout_width="fill_parent"
            android:layout_height="1dip"
            android:background="#CCEEEEEE"
            android:padding="10dip"
        />
    </LinearLayout>

    <ScrollView  xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:layout_weight="1"
        >

        <!-- Insert your regular layout stuff here -->

        <Button android:id="@+id/toggle_title_button" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:text="Toggle Title" 
        />
    </ScrollView>
</LinearLayout>

And here is the code for the main activity that will allow you to toggle our custom title bar on and off

这里是主要活动的代码,允许您打开和关闭我们的自定义标题栏

package com.snctln.test.HelloGridView;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class HelloGridView extends Activity
{
    public void onCreate(Bundle savedInstanceState)
    {
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TextView tv = (TextView)this.findViewById(R.id.myTitleBarTextView);
        tv.setBackgroundColor(0xFF848284);
        tv.setTextColor(0xFFFFFFFF);

        Button toggleTitleButton = (Button)this.findViewById(R.id.toggle_title_button);

        toggleTitleButton.setOnClickListener( new OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    LinearLayout ll = (LinearLayout)findViewById(R.id.myTitleBarLayout);

                    if(ll.getVisibility() == View.GONE)
                    {
                        ll.setVisibility(View.VISIBLE);
                    }
                    else
                    {
                        ll.setVisibility(View.GONE);
                    }
                }
            });
    }
}

It doesn't look perfect, but you can always play with the layout some more to do that.

它看起来并不完美,但你可以随时使用布局来做到这一点。

alt text http://i39.tinypic.com/120sfp1.png

替代文字http://i39.tinypic.com/120sfp1.png

My other thought is if you just want to hide everything to show a progress bar why not use the ProgressDialog?

我的另一个想法是,如果你只想隐藏所有内容以显示进度条,为什么不使用ProgressDialog?

This class is pretty easy to use...

这个类很容易使用......

progressDlg = ProgressDialog.show(context, getString(R.string.progress_dialog_title_prepare), getString(R.string.progress_dialog_body_prepare));

// do long running operation

if(operationFailed)
{
    progressDlg.cancel();
}
else
{
    progressDlg.dismiss();
}

#2


13  

Adding android:theme="@android:style/Theme.NoTitleBar.Fullscreen" to application tag in the manifest file will make every activity fullscreen.

将android:theme =“@ android:style / Theme.NoTitleBar.Fullscreen”添加到清单文件中的应用程序标记将使每个活动全屏显示。

#3


11  

To disable the title of your application (it is the app name)

禁用应用程序的标题(它是应用程序名称)

requestWindowFeature(Window.FEATURE_NO_TITLE)

To disable the notification bar on the top (so a request to the android app manager to allow Fullscreen)

要禁用顶部的通知栏(因此请求Android应用程序管理器允许全屏)

getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN)

Hope this helps any one who wants to know the difference!!

希望这能帮助任何想要了解差异的人!

#4


10  

if(useFullscreen)  
{  
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);  
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);  
}  
else  
{  
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);  
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);  
}  

this worked for me .. at onResume method

这对我有用..在onResume方法

#5


3  

On Android 3+ it can be easilyy achieved by calling getActionBar().hide() and getActionBar().show() to respectively show and hide the standard ActionBar

在Android 3+上,可以通过调用getActionBar()。hide()和getActionBar()。show()分别显示和隐藏标准ActionBar来轻松实现。

On Android 1,2 the best solution (I guess) is to implement custom View for yout "title bar" and hide it on demand (of course, calling to requestWindowFeature(Window.FEATURE_NO_TITLE); at the beginning).

在Android 1,2上,最好的解决方案(我猜)是为你的“标题栏”实现自定义View并按需隐藏它(当然,调用requestWindowFeature(Window.FEATURE_NO_TITLE);在开头)。

#6


1  

that is not possible according to the docs and the android-developers google group. to implement that , you need to add a 'title-bar-like' layout item with your text and progress bar and hide/show when you need it. right now - no other way around it, since title bar control can be done only before the setContentView call and not changed after.

根据文档和Android开发人员谷歌组不可能。要实现这一点,您需要在文本和进度条中添加“标题栏”布局项,并在需要时隐藏/显示。现在 - 没有其他方法,因为标题栏控件只能在setContentView调用之前完成,之后不会更改。