设置Activity无标题栏

设置activity无标题栏

1.设置清单文件主题样式如下
 <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".Main" android:theme="@android:style/Theme.DeviceDefault.NoActionBar
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

在activity里设置android:theme="@android:style/Theme.DeviceDefault.NoActionBar
2.设置java代码继承类
public class Main extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);
    }
}

把当前继承的AppCompatActivity类换成Activity
如下:
    public class Main extends Activity 
3.样式大全
Theme.Dialog : (图1)Activity显示为对话框模式
Theme.NoTitleBar : (图2)不显示应用程序标题栏
Theme.NoTitleBar.Fullscreen : (图3)不显示应用程序标题栏,并全屏
Theme.Light : (图4)背景为白色
Theme.Light.NoTitleBar : (图5)白色背景并无标题栏
Theme.Light.NoTitleBar.Fullscreen : (图6)白色背景,无标题栏,全屏
Theme.Black : (图7)背景黑色
Theme.Black.NoTitleBar : (图8)黑色背景并无标题栏
Theme.Black.NoTitleBar.Fullscreen : (图9)黑色背景,无标题栏,全屏
Theme.Wallpaper : (图10)用系统桌面为应用程序背景
Theme.Wallpaper.NoTitleBar : (图11) 用系统桌面为应用程序背景,且无标题栏
Theme.Wallpaper.NoTitleBar.Fullscreen : (图12)用系统桌面为应用程序背景,无标题栏,全屏
Theme.Translucent : (图13)透明背景
Theme.Translucent.NoTitleBar : (图14)透明背景并无标题
Theme.Translucent.NoTitleBar.Fullscreen : (图15)透明背景并无标题,全屏
Theme.Panel : (图16)面板风格显示
Theme.Light.Panel : (图17)平板风格显示
一、通过Java代码
在setContentView之前执行:
requestWindowFeature(Window.FEATURE_NO_TITLE);//隐藏标题栏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);//隐藏状态栏
二、调用Android自带的Theme
直接在AndroidManifest.xml中需要全屏显示的Activity属性中添加
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" // 不显示应用程序标题栏,并全屏 
android:theme="Theme.Light.NoTitleBar.Fullscreen" // 白色背景,无标题栏,全屏
android:theme="Theme.Black.NoTitleBar.Fullscreen" // 黑色背景,无标题栏,全屏
三、自己定义全屏Theme
在style.xml文件中定义theme(如果没有style.xml,在res/values目录下创建)
<resources> 
<style name="Theme.NoTitle_FullScreen"> <!--自定义主题名称-->
<item name="android:windowNoTitle">true</item> 
<item name="android:windowFullscreen">true</item> 
</style> 
</resources>
posted @ 2017-06-19 09:42  勤能补拙Android  阅读(10933)  评论(0编辑  收藏  举报