隐藏标题在全屏模式? [英] Hiding Title in a Fullscreen mode?

查看:197
本文介绍了隐藏标题在全屏模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法隐藏窗口标题,这样它不会在全屏模式下显示(

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.

推荐答案

我的方式处理这在我的Andr​​oid游戏是要叫我的活动中的onCreate以下行()

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

requestWindowFeature(Window.FEATURE_NO_TITLE);

我就可以打开全屏幕功能关闭,使用下面的code在我的活动类(通常是从一个菜单选项调用)(该m_contentView变量是从findViewById()使用您使用的ID视图调用的setContentView()在上创建)时

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)

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.

为什么这么说呢

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

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

:::

那么,如果你试图动态显示,我不知道如果你能做到这一点与官方的窗口标题,由于注意到该活动已经提到的窗口,在一生中隐藏它的功能需要之前,必须设置的setContentView()被调用(<一href="http://developer.android.com/reference/android/view/Window.html#requestFeature%28int%29">link)

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)

这是你可以做的是实现自己的标题栏和动态显示和隐藏了一件事......我放在一起这个例子,应该设置你O n此正确的轨道

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

下面是布局文件

<?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>

这里是code的主要活动,让您切换我们的自定义标题栏和关闭

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.

我的另一个想法是,如果你只是想隐藏一切显示进度条为什么不使用<一个href="http://developer.android.com/reference/android/app/ProgressDialog.html">ProgressDialog?

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

这个类是pretty的易于使用的...

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();
}

这篇关于隐藏标题在全屏模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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