在开发中经常需要把我们的应用设置为全屏,这里我所知道的有俩中方法,一中是在代码中设置,另一种方法是在配置文件里改!

一、在代码中设置:

import android.app.Activity; import android.os.Bundle; import android.view.Window; import android.view.WindowManager; public class Demo extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //无title requestWindowFeature(Window.FEATURE_NO_TITLE); //全屏 getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN , WindowManager.LayoutParams. FLAG_FULLSCREEN); setContentView(R.layout.main); } }

在这里要强调一点,设置全屏的俩段代码必须在setContentView(R.layout.main) 之前,不然会报错。

二、在配置文件里修改(android:theme="@android:style/Theme.NoTitleBar.Fullscreen"):

<?xml version="1.0" encoding="utf-8"?>

在这里我还想说明一下,用前者在我们应用运行后,会看到短暂的状态栏,然后才全屏,而第二种方法是不会有这种情况的,所以我建议

大家使用后者.

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------

android横竖屏切换:

public class screenOrientation extends Activity{  private TextView mTextView01;  private Button mButton01;  /** Called when the activity is first created. */  @Override  public void onCreate(Bundle savedInstanceState)  {    super.onCreate(savedInstanceState);    setContentView(R.layout.main);    mButton01 = (Button) findViewById(R.id.myButton1);    mTextView01 = (TextView) findViewById(R.id.myTextView1);    /**     * 需要注意的是要在AndroidManifest.xml/n添加android:screenOrientation属性     */    if (getRequestedOrientation() == -1)    {      mTextView01.setText(getResources().getText(0,          "请添加android:screenOrientation属性  "));    }    /* 当点击按钮旋转屏幕画面 */    mButton01.setOnClickListener(new Button.OnClickListener()    {      @Override      public void onClick(View arg0)      {        /* 方法一:重写getRequestedOrientation */        /* 若无法取得screenOrientation属性 */        if (getRequestedOrientation() == -1)        {          /* 提示无法进行画面旋转功能,因无法判别Orientation */          mTextView01.setText(getResources().getText(R.string.str_err_1001));        } else        {          if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)          {            /* 若当下为横排,则更改为竖排呈现 */            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);          } else if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)          {            /* 若当下为竖排,则更改为横排呈现 */            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);          }        }      }    });  }  /**   * 若要通过程序改变屏幕的方向,必须要覆盖setRequestedOrientation()方法,   * 而若要取得当下的屏幕方向,必须要访问getRequestedOrientation()方法。   * 在AndroidManifest.xml中需要设置android   * :screenOrientation属性,否则将无法通过getRequestedOrientation()来判断Activity的方向。   *    * @param requestedOrientation   */  @Override  public void setRequestedOrientation(int requestedOrientation)  {    // TODO Auto-generated method stub    /* 判断要更改的方向,以Toast提示 */    switch (requestedOrientation)    {      /* 更改为LANDSCAPE */      case (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE):        mMakeTextToast(getResources().getText(R.string.str_msg1).toString(),            false);        break;      /* 更改为PORTRAIT */      case (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT):        mMakeTextToast(getResources().getText(R.string.str_msg2).toString(),            false);        break;    }    super.setRequestedOrientation(requestedOrientation);  }  @Override  public int getRequestedOrientation()  {    // TODO Auto-generated method stub    /* 此重写getRequestedOrientation方法,可取得当下屏幕的方向 */    return super.getRequestedOrientation();  }  public void mMakeTextToast(String str, boolean isLong)  {    if (isLong == true)    {      Toast.makeText(screenOrientation.this, str, Toast.LENGTH_LONG).show();    } else    {      Toast.makeText(screenOrientation.this, str, Toast.LENGTH_SHORT).show();    }  }}


 

更多相关文章

  1. Android 保存文件路径方法
  2. 阻止一进入页面就弹输入法对话框的方法
  3. Android中SQLiteOpenHelper类的onUpgrade方法的作用
  4. 一张图看遍LinearLayout的所有特有属性
  5. android TabHost(选项卡)的使用方法
  6. Android使用系统方法实现分享到QQ和微信!

随机推荐

  1. [置顶] Android学习进阶路线导航线路(And
  2. Android中贪吃蛇游戏的学习(四)
  3. [置顶] Android开发之ScrollView去掉右侧
  4. 2011.07.18——— android AlphaBitmap
  5. android apk的安装
  6. Android(安卓)studio 启动出现错误AAPT:
  7. Android中各种onTouch事件
  8. android 解决eclipse无法更新SDK问题
  9. android 修改谷歌拼音输入法全屏时的高度
  10. Java建造者模式,Android建造者模式的Alert