[英]No Title Bar Android Theme
在我的應用程序中我想使用Theme.NoTitleBar,但另一方面我也不想放松Android操作系統的內部主題..我在網上搜索並找到以下答案..我修改了我的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>
內部值-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 / 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>
在Manifest文件的應用程序標記中,我添加了一個屬性:
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>
如果您希望保留Ui的原始樣式並刪除標題欄而不影響該標題欄,則必須刪除活動中的標題欄而不是清單。 保留您在清單和每個活動中所擁有的原始主題樣式,沒有標題欄使用this.requestWindowFeature(Window.FEATURE_NO_TITLE);
在oncreate()
之前方法setcontentview()
是這樣的:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_signup);
...
}
若要隱藏操作欄,請在“值/樣式”中添加以下代碼
<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>
在您的清單使用中: -
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>
令人驚訝的是,這可以滿足您的需求,在AppTheme中使用AppBaseTheme的同一父母則不然。
你為什么要改變android os內置主題 。
根據您的活動要求您必須以這種方式實施
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
根據@arianoo
說法,你必須使用這個功能。
我認為這是隱藏標題欄主題的更好方法。
在清單文件的應用程序標簽中使用android:theme="@android:style/Theme.NoTitleBar
刪除整個應用程序的標題欄,或將其放在活動標簽中以從單個活動屏幕中刪除標題欄。
在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.