简体   繁体   English

没有标题栏Android主题

[英]No Title Bar Android Theme

In my application I want to use the Theme.NoTitleBar, but on the other hand I also don't want to loose the internal Theme of the Android OS.. I searched on the net and Found the following answer.. I have modified my styles.xml and added the following line of code.. 在我的应用程序中我想使用Theme.NoTitleBar,但另一方面我也不想放松Android操作系统的内部主题..我在网上搜索并找到以下答案..我修改了我的styles.xml并添加了以下代码行..

Inside values/styles.xml 内部值/ 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>

Inside values-v11/styles.xml 内部值-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>

Inside values-v14/styles.xml 内部值-v14 / styles.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>

In the application tag of the Manifest file I have added an attribute of: 在Manifest文件的应用程序标记中,我添加了一个属性:

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

But when I try to run the code The images in my application gets Blurry.. But when I use the following tag: 但是当我尝试运行代码时我的应用程序中的图像变得模糊..但是当我使用以下标记时:

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

or 要么

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

or 要么

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

The images in the application comes in the correct form... But In this case I lose all the themes on the new Android OS.. 应用程序中的图像格式正确...但在这种情况下,我丢失了新Android操作系统上的所有主题..

Please help me how can I use NoTitleBar Theme without loosing the Images and the Native Theme.. 请帮助我如何在不丢失图像和原生主题的情况下使用NoTitleBar主题..

Code for the layout: 布局代码:

<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>

图像变得模糊

if you want the original style of your Ui to remain and the title bar to be removed with no effect on that, you have to remove the title bar in your activity rather than the manifest. 如果您希望保留Ui的原始样式并删除标题栏而不影响该标题栏,则必须删除活动中的标题栏而不是清单。 leave the original theme style that you had in the manifest and in each activity that you want no title bar use this.requestWindowFeature(Window.FEATURE_NO_TITLE); 保留您在清单和每个活动中所拥有的原始主题样式,没有标题栏使用this.requestWindowFeature(Window.FEATURE_NO_TITLE); in the oncreate() method before setcontentview() like this: oncreate() 之前方法setcontentview()是这样的:

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

To Hide the Action Bar add the below code in Values/Styles 若要隐藏操作栏,请在“值/样式”中添加以下代码

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

Then in your AndroidManifest.xml file add the below code in the required activity 然后在AndroidManifest.xml文件中,在所需活动中添加以下代码

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

In your manifest use:- 在您的清单使用中: -

    android:theme="@style/AppTheme" >

in styles.xml:- 在styles.xml中: -

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

Surprisingly this works as yo desire, Using the same parent of AppBaseTheme in AppTheme does not. 令人惊讶的是,这可以满足您的需求,在AppTheme中使用AppBaseTheme的同一父母则不然。

Why are you changing android os inbuilt theme . 你为什么要改变android os内置主题

As per your activity Require You have to implements this way 根据您的活动要求您必须以这种方式实施

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

as per @arianoo says you have to used this feature. 根据@arianoo说法,你必须使用这个功能。

I think this is better way to hide titlebar theme. 我认为这是隐藏标题栏主题的更好方法

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

In your styles.xml, modify style "AppTheme" like 在styles.xml中,修改样式“AppTheme”就好

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <item name="android:windowActionBar">false</item>
        <item name="android:windowNoTitle">true</item> 
    </style>
 this.requestWindowFeature(getWindow().FEATURE_NO_TITLE);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM