2013-02-04 168 views
15

在我的应用程序中,我想使用Theme.NoTitleBar,但另一方面,我也不想松动Android操作系统的内部主题..我在网上搜索和找到以下的答案。我已经修改了我的styles.xml并添加下面的代码行..没有标题栏Android主题

内值/ styles.xml

<style name="Theme.Default" parent="@android:style/Theme"></style> 
<style name="Theme.NoTitle" parent="@android:style/Theme.NoTitleBar"></style> 
<style name="Theme.FullScreen" parent="@android:style/Theme.NoTitleBar.Fullscreen"></style> 

内值-V11/styles.xml

<style name="Theme.Default" parent="@android:style/Theme.Holo"></style> 
<style name="Theme.NoTitle" parent="@android:style/Theme.Holo.NoActionBar"></style> 
<style name="Theme.FullScreen" parent="@android:style/Theme.Holo.NoActionBar.Fullscreen"></style> 

内部值-v14 /手术es.xml

<style name="Theme.Default" parent="@android:style/Theme.Holo.Light"></style> 
<style name="Theme.NoTitle" parent="@android:style/Theme.Holo.Light.NoActionBar"></style> 
<style name="Theme.FullScreen" parent="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen"></style> 

清单文件的应用标签我添加的属性:

android:theme="@style/Theme.NoTitle" 

但是当我尝试运行代码在我的应用程序中的图像变得模糊。但是当我用下面的标签:

android:theme="@android:style/Theme.NoTitleBar" 

android:theme="@android:style/Theme.Light.NoTitleBar" 

android:theme="@android:style/Theme.Black.NoTitleBar" 

在应用程序中的图像来以正确的形式......但在这种情况下,我失去了新的Android操作系统的所有主题..

请帮助我如何能我用NoTitleBar主题没有松动的图像和本土主题..

代码布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/mainScreen" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context=".MainActivity" > 

<include 
    android:id="@+id/main_top_bar" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    layout="@layout/top_bar_title" /> 

<RelativeLayout 
    android:id="@+id/container_bar1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/main_top_bar" 
    android:layout_marginTop="-3dp" 
    android:background="@drawable/tab_nav_bar" > 
</RelativeLayout> 

<RelativeLayout 
    android:id="@+id/container_bar2" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/container_bar1" 
    android:background="@drawable/location_nav_bar" > 

    <TableLayout 
     android:id="@+id/map_bar" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_marginLeft="10dp" 
     android:paddingBottom="5dp" 
     android:background="@drawable/map_bar_bg" > 

     <TableRow 
      android:id="@+id/tableRow1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

      <Button 
       android:id="@+id/MapPointer" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="8dp" 
       android:background="@drawable/map_pointer" /> 

      <TextView 
       android:id="@+id/MapSeperator" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="2dp" 
       android:layout_marginTop="2dp" 
       android:text="|" 
       android:textColor="#979ca0" 
       android:textSize="20dp" /> 

      <com.pnf.myevent.CustomTextView 
       android:id="@+id/DisplayLocation" 
       android:layout_width="80dp" 
       android:layout_height="wrap_content" 
       android:ellipsize="marquee" 
       android:fadingEdge="horizontal" 
       android:marqueeRepeatLimit="marquee_forever" 
       android:paddingLeft="5dp" 
       android:scrollHorizontally="true" 
       android:singleLine="true" 
       android:textColor="#adabad" 
       android:textSize="12dp" /> 

      <Button 
       android:id="@+id/RefreshBtn" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="3dp" 
       android:background="@drawable/refresh_button" /> 
     </TableRow> 
    </TableLayout> 

    <TableLayout 
     android:id="@+id/calendar_bar" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:layout_marginRight="10dp" > 

     <TableRow 
      android:id="@+id/tableRow2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

      <Button 
       android:id="@+id/MonthBtn" 
       android:layout_width="40dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:background="@drawable/month_button" /> 

      <Button 
       android:id="@+id/TodayBtn" 
       android:layout_width="40dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:background="@drawable/today_button" /> 

      <Button 
       android:id="@+id/WeekBtn" 
       android:layout_width="40dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:background="@drawable/week_button" /> 
     </TableRow> 
    </TableLayout> 
</RelativeLayout> 

<RelativeLayout 
    android:id="@+id/container_bar3" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/container_bar2" 
    android:background="@drawable/cal_nav_bar" > 

    <Button 
     android:id="@+id/CalPrevious" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_marginLeft="30dp" 
     android:layout_marginTop="5dp" 
     android:background="@drawable/left_arrow_button" /> 

    <com.pnf.myevent.CustomTextView 
     android:id="@+id/CalTitle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="5dp" 
     android:shadowColor="#ffffff" 
     android:shadowDx="0" 
     android:shadowDy="2" 
     android:shadowRadius="1" 
     android:text="Title" 
     android:textColor="#666666" 
     android:textSize="15dp" /> 

    <Button 
     android:id="@+id/CalNext" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_marginRight="30dp" 
     android:layout_marginTop="5dp" 
     android:background="@drawable/right_arrow_button" /> 
</RelativeLayout> 

<RelativeLayout 
    android:id="@+id/container_bar4" 
    android:layout_width="match_parent" 
    android:layout_height="200dp" 
    android:layout_below="@+id/container_bar3" 
    android:background="#c8c9cc" > 

    <GridView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/gridView1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="center" 
     android:horizontalSpacing="2dp" 
     android:listSelector="#00000000" 
     android:numColumns="7" 
     android:stretchMode="columnWidth" 
     android:verticalSpacing="2dp" /> 
</RelativeLayout> 

<RelativeLayout 
    android:id="@+id/footer_bar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/container_bar4" > 

    <ListView 
     android:id="@+id/CalendarList" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:listSelector="#00000000" 
     android:cacheColorHint="#00000000" 
     android:divider="#dedede" 
     android:dividerHeight="1dp" 
     android:drawSelectorOnTop="false" /> 
</RelativeLayout> 

Images Getting Blurry

+0

你不设置没有标题栏松动Android的主题。你在XML布局中做错了什么。请张贴布局,以便我们可以查看。所有Android平台版本都会发生这种情况吗?或者只是一个特定的一个 –

+0

它发生在所有平台上。我已经在layout-ldpi,layout-mdpi,layout-hdpi和layout-xhdpi等红色文件夹中创建了布局文件夹,并且还为不同屏幕提供了包含不同图像的可绘制文件夹。屏幕截图来自galaxy s3,但同样在仿真器上 –

+0

您可以发布其中一种布局吗?除非有特殊情况,否则不需要基于dpi的不同布局。 –

回答

29
如果你想你的用户界面的原有风格保持和标题栏

与上没有效果被移除,你必须删除标题栏在您的活动,而不是清单。留下您的清单,并在您要没有标题栏setcontentview()这样之前在oncreate()方法使用this.requestWindowFeature(Window.FEATURE_NO_TITLE);每项活动有原始的主题风格:

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    setContentView(R.layout.activity_signup); 
    ... 
} 
+7

这个工程,但这不是最好的解决方案,标题栏闪烁之前一些secod – abovesun

+0

thnks它为我工作..沃特达 – 2015-01-24 07:25:07

+0

我在这个确切的顺序中使用了相同的行,但是我得到了这样的想法:'必须在添加内容之前调用'android.util.AndroidRuntimeException:requestFeature()' - 任何人都知道为什么? – GyRo

3

为什么要改变Android操作系统内置主题

根据你的活动要求你必须按照@arianoo说你必须用这个功能来实现这样

this.requestWindowFeature(Window.FEATURE_NO_TITLE); 

我认为这是更好的方式隐藏标题栏主题。

0
this.requestWindowFeature(getWindow().FEATURE_NO_TITLE); 
+0

会更“正确”像这样:'requestWindowFeature(android.view.Window.FEATURE_NO_TITLE); ' – Reinherd

20

要隐藏操作栏添加下面的代码在价值/样式

<style name="CustomActivityThemeNoActionBar" parent="@android:style/Theme.Holo.Light"> 
    <item name="android:windowActionBar">false</item> 
    <item name="android:windowNoTitle">true</item> 
</style> 

然后在你的AndroidManifest.xml文件中添加以下代码所需的活动

<activity 
     android:name="com.newbelievers.android.NBMenu" 
     android:label="@string/title_activity_nbmenu" 
     android:theme="@style/CustomActivityThemeNoActionBar"> 
</activity> 
+4

“机器人:windowActionBar”需要API +11 所以,因为我的相容性+8,“机器人:windowNoTitle”的伎俩 谢谢;) –

7

在您的清单中使用: -

android:theme="@style/AppTheme" > 

在styles.xml: -

<!-- Application theme. --> 
<style name="AppTheme" parent="AppBaseTheme"> 
     <item name="android:windowActionBar">false</item> 
    <item name="android:windowNoTitle">true</item> 
</style> 

令人惊讶的这部作品作为哟欲望,使用AppBaseTheme的AppTheme同家长不。

+0

谢谢你救了我 –

+0

惊喜惊喜多多,什么是这个页面上工作为了我。我怀疑我应该停止扩展'ActionBarActivity',以支持vanilla'Activity'。即使像'requestWindowFeature(Window.FEATURE_NO_TITLE);'简单的FC这样残酷的事情。 – John

1

在清单文件的应用程序标记中使用android:theme="@android:style/Theme.NoTitleBar可以删除整个应用程序的标题栏,或者将它放在活动标记中以从单个活动屏幕删除标题栏。

1

在你styles.xml,修改样式“AppTheme”像

<!-- Application theme. --> 
    <style name="AppTheme" parent="AppBaseTheme"> 
     <item name="android:windowActionBar">false</item> 
     <item name="android:windowNoTitle">true</item> 
    </style>