如何隐藏 activity 无标题栏的标题栏

android 去掉actionbar 隐藏标题栏 全屏 - kaixinkaixin0 - 推酷
android 去掉actionbar 隐藏标题栏 全屏 - kaixinkaixin0
去掉actionbar :getActionBar().hide();
全屏方法一:
&&&&&&&&&&& android:name=&com.imax.weather.MainActivity&
&&&&&&&&&&& android:label=&@string/app_name&
&&&&&&&&&&& android:screenOrientation=&portrait&
&&&&&&&&&&&
android:theme=&@android:style/Theme.NoTitleBar.Fullscreen&
&&&&&&&&&&& &intent-filter&
&&&&&&&&&&&&&&& &action android:name=&android.intent.action.MAIN& /&
&category android:name=&android.intent.category.LAUNCHER& /&
&&&&&&&&&&& &/intent-filter&
&&&&&&& &/activity&
onCreate(Bundle savedInstanceState)
.onCreate(savedInstanceState);
隐去标题栏
(应用程序的名字)&
requestWindowFeature(
.FEATURE_NO_TITLE);
全屏方法二
:隐去状态栏部分 (电池等图标和一切修饰部分)
getWindow().setFlags(
WindowManager
.LayoutParams.FLAG_FULLSCREEN,
WindowManager
.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致Icansoft 的BLOG
用户名:Icansoft
文章数:127
评论数:244
访问量:3724610
注册日期:
阅读量:5863
阅读量:12276
阅读量:359909
阅读量:1055845
51CTO推荐博文
1.&标题栏显示图标public void onCreate(Bundle savedInstanceState) {&&&&&&&&super.onCreate(savedInstanceState);&&&&&&&&requestWindowFeature(Window.FEATURE_LEFT_ICON);&&&&&&&&setContentView(R.layout.main);&&&& &&&&&&&&getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,&&&&&&&&&&&&&&&&&&&&&&&&android.R.drawable.icon);&&&&&&&&// ...}但实际效果呢,我觉得不好看,和旁边的文字有相当距离!看看别人的图片的:650) this.width=650;" src="../attachment/944760.png" border="0" alt="" />当然这个图标也可以通过自定义布局,使用ImageView来实现:&?xml version="1.0" encoding="utf-8"?&&LinearLayout xmlns:android="/apk/res/android"&&&&&&&&android:layout_width="wrap_content"&&&&&&&&android:layout_height="wrap_content" &&&&&&ImageView android:layout_width="wrap_content"&&&&&&&&&&&&&&&&android:layout_height="wrap_content"&&&&&&&&&&&&&&&&android:src="@drawable/icon"/&&&&&&TextView android:id="@+id/text"&&&&&&&&&&&&&&&&android:layout_width="wrap_content"&&&&&&&&&&&&&&&&android:layout_height="wrap_content"&&&&&&&&&&&&&&&&android:layout_alignParentLeft="true"&&&&&&&&&&&&&&&&android:text="文本" /&&&&&&/LinearLayout&效果图:650) this.width=650;" src="../attachment/821751.png" border="0" alt="" />2.自定义布局看看我自定义的标题栏:650) this.width=650;" src="../attachment/802165.png" border="0" alt="" />布局代码(titlebar.xml)&?xml version="1.0" encoding="utf-8"?&&LinearLayout&&&&&&&&xmlns:android="/apk/res/android"&&&&&&&&android:orientation="horizontal"&&&&&&&&android:layout_width="fill_parent"&&&&&&&&android:layout_height="wrap_content"&&&&&&&&&&TextView&&&&&&&&&&&&&&&&android:text="@string/app_name"&&&&&&&&&&&&&&&&android:textColor="#000"&&&&&&&&&&&&&&&&android:paddingRight="3.0dip"&&&&&&&&&&&&&&&&android:layout_width="wrap_content"&&&&&&&&&&&&&&&&android:layout_height="wrap_content"/&&&&&&&&&&TextView&&&&&&&&&&&&&&&&android:text="@string/battery_text"&&&&&&&&&&&&&&&&android:textColor="#000"&&&&&&&&&&&&&&&&android:paddingRight="3.0dip"&&&&&&&&&&&&&&&&android:layout_width="wrap_content"&&&&&&&&&&&&&&&&android:layout_height="wrap_content"/&&&&&&&&&&TextView&&&&&&&&&&&&&&&&android:id="@+id/battery_text"&&&&&&&&&&&&&&&&android:textColor="#00f"&&&&&&&&&&&&&&&&android:layout_width="wrap_content"&&&&&&&&&&&&&&&&android:layout_height="wrap_content"/&&/LinearLayout&Java代码:public void onCreate(Bundle savedInstanceState) {&&&&&&&&super.onCreate(savedInstanceState);&&&&&&&&requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); &&&&&&&&setContentView(R.layout.main);&&&&&&&&//自定义标题栏&&&&&&&&mWindow = getWindow();&&&&&&&&mWindow.setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.titlebar);&&&&&&&&mBatteryText = (TextView)findViewById(R.id.battery_text);&&&&&&&&mBatteryInforeceiver = new BroadcastReceiver(){&&&&&&&&&&&& @Override&&&&&&&&&&&& public void onReceive(Context context, Intent intent) {&&&&&&&&&&&&&&&&&&&& int level = intent.getIntExtra("level", 0);&&&&&&&&&&&&&&&&&&&& int scale = intent.getIntExtra("scale", 1);&&&&&&&&&&&&&&&&&&&& mBatteryText.setText(String.valueOf((int)(level*100/scale))+"%");&&&&&&&&&&&& }&&&&&&&&&&&& &&&&&&&&};}你还可以添加其他控件,而这些控件的获取和事件响应都是直接在activity里面完成。3. 设置标题栏的背景色和高度虽然我们可以通过自定义布局文件在标题栏加入一些控件,但是仍然不能改变标题栏的高度、背景色,要想达到这个目的,只能使用theme(主题)。\res\values\style.xml:&?xml version="1.0" encoding="utf-8"?&&resources&&&&&&&&&&style name="CustomWindowTitleBackground"&&&&&&&&&&&&&&&&&&item name="android:background"&#47B2FF&/item&&&&&&&&&&/style&&&&&&&&&&style name="activityTitlebar" parent="android:Theme"&&&&&&&&&&&&&&&&&&item name="android:windowTitleSize"&34dp&/item& &!-- 高度 --&&&&&&&&&&&&&&&&&&item name="android:windowTitleBackgroundStyle"&@style/CustomWindowTitleBackground&/item&&&&&&!-- 背景色,需要调用前面的颜色设置 --&&&&&&&&&&/style&&/resources&窗体显示状态操作(requestWindowFeature()的应用)首先介绍一个重要方法那就是requestWindowFeature(featrueId),它的功能是启用窗体的扩展特性。参数是Window类中定义的常量。一、枚举常量1.DEFAULT_FEATURES:系统默认状态,一般不需要指定2.FEATURE_CONTEXT_MENU:启用ContextMenu,默认该项已启用,一般无需指定3.FEATURE_CUSTOM_TITLE:自定义标题。当需要自定义标题时必须指定。如:标题是一个按钮时4.FEATURE_INDETERMINATE_PROGRESS:不确定的进度5.FEATURE_LEFT_ICON:标题栏左侧的图标6.FEATURE_NO_TITLE:没标题7.FEATURE_OPTIONS_PANEL:启用“选项面板”功能,默认已启用。8.FEATURE_PROGRESS:进度指示器功能9.FEATURE_RIGHT_ICON:标题栏右侧的图标对于默认启用的和前面有介绍的就略去不提了。我们说比较常用的FEATURE_INDETERMINATE_PROGRESS和FEATURE_NO_TITLE。FEATURE_INDETERMINATE_PROGRESS:表示一个进程正在运行progress.xml&?xml version="1.0" encoding="utf-8"?&&LinearLayout xmlns:android="/apk/res/android"&&&&android:layout_width="wrap_content"&&&&android:layout_height="wrap_content"&&&&&&ProgressBar android:id="@+id/progress"&&&&&&&&&&&&android:layout_width="wrap_content"&&&&&&&&&&&&android:layout_height="wrap_content"&&&& &&&&&&&&&&&&android:layout_gravity="center_vertical"&&&&&&&&&&&&style="?android:attr/progressBarStyleSmallTitle"&&&&&&/ProgressBar&&/LinearLayout&Java代码public void onCreate(Bundle savedInstanceState) {&&&&&&&&super.onCreate(savedInstanceState);&&&&&&&&requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);&&&&&&&&setContentView(R.layout.main);&&&&&&&&getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS, R.layout.progress);&&&&&&&&setProgressBarIndeterminateVisibility(true); //适当时候set false来隐藏&&&&&&&&//...}标题进度条显示650) this.width=650;" src="../attachment/226404.png" border="0" alt="" />FEATURE_NO_TITLE 就是不显示标题栏,某些时候全屏需要,但全屏不等于不显示标题栏,我尝试显示标题栏的同时全屏来去掉系统的状态栏:Java代码public void onCreate(Bundle savedInstanceState) {&&&&&&&&super.onCreate(savedInstanceState);&&&&&&&&requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); &&&&&&&&setContentView(R.layout.main);&&&&&&&&//自定义标题栏&&&&&&&&mWindow = getWindow();&&&&&&&&mWindow.setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.titlebar);&&&&&&&&/* full screen */&&&&&&&&mWindow.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,&&&&&&&&&&&&&&&&&&&&&&&&WindowManager.LayoutParams.FLAG_FULLSCREEN);&&&&&&&&// ...}所以真正实现全屏的是后面的那句话!效果图650) this.width=650;" src="../attachment/836825.png" border="0" alt="" />***********本文部分内容摘录于《Android 应用程序窗体显示状态操作(requestWindowFeature()的应用)》
了这篇文章
类别:┆阅读(0)┆评论(0)
14:54:59 15:53:55 14:22:217460人阅读
翻译教程_translation(84)
本章节翻译自《Beginning-Android-4-Application-Development》,如有翻译不当的地方,敬请指出。原书购买地址如果愿意的话,可以把Activity的标题栏给隐藏了。只需要调用requestWindowFeature()方法,同时传递Window.FEATURE_NO_TITLE常量。public class Activity101Activity extends Activity {
String tag = &Lifecycle&;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ---hides the title bar---
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:2412405次
积分:14858
积分:14858
排名:第558名
原创:127篇
转载:28篇
译文:60篇
评论:354条
文章:85篇
阅读:564734
(2)(3)(7)(2)(2)(11)(31)(31)(3)(8)(30)(11)(5)(1)(4)(1)(1)(1)(5)(1)(2)(53)}

我要回帖

更多关于 activity不显示标题栏 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信