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

一、在代码中设置:

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. visual studio2019 Android(安卓)SDK API28出现“ERR_CLEARTEXT_
  2. 如何设置Activity全屏显示和没有Title
  3. Android中取消GridView & ListView默认的点击背景色
  4. Android(安卓)Intent传递对象
  5. Android(安卓)CountDownTimer的使用
  6. android IOS在WebView 和 JS 交互对比
  7. Unity3D 调用Android原生方法
  8. 浅谈Java中Collections.sort对List排序的两种方法
  9. Python list sort方法的具体使用

随机推荐

  1. 【Android】关于百分比布局多个LinearLay
  2. 山寨机翻身的日子可能快到了
  3. 实战:Android活动目录LiveFolder开发
  4. 百度语音合成(TTS) 在Android的使用方法
  5. Android平台手机 5大优势和劣势
  6. Unity与Android通信优化方案
  7. Android(安卓)自定义控件之组合控件
  8. Android——Intent在Activity的使用详解-
  9. Glide源码解析篇之框架主体结构(一)
  10. 00003 不思议迷宫.0011.2:Android新版中的