2013-02-04 40 views
15

Trong ứng dụng của tôi, tôi muốn sử dụng Theme.NoTitleBar, nhưng mặt khác tôi cũng không muốn mất Theme nội bộ của hệ điều hành Android .. Tôi tìm kiếm trên mạng và tìm thấy sau câu trả lời .. tôi đã sửa đổi styles.xml của tôi và thêm các dòng mã sau đây ..No Title Bar Android Theme

giá trị bên trong/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> 

Bên trong giá trị-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> 

Giá trị bên trong-v14/kiểu 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> 

Trong ứng dụng tag của tập tin Manifest Tôi đã thêm một thuộc tính của:

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

Nhưng khi tôi cố gắng chạy mã Hình ảnh trong ứng dụng của tôi bị mờ. . Nhưng khi tôi sử dụng thẻ sau:

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

hoặc

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

hoặc

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

Những hình ảnh trong ứng dụng đi kèm trong các hình thức đúng ... Nhưng Trong trường hợp này, tôi mất tất cả các chủ đề trên hệ điều hành Android mới ..

Xin hãy giúp tôi làm thế nào có thể tôi sử dụng NoTitleBar Theme mà không mất các hình ảnh và các Theme Native ..

Mã cho bố trí:

<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

Bạn không mất chủ đề Android bằng cách thiết lập không có thanh tiêu đề. Bạn đang làm điều gì sai trong bố cục XML của mình. Vui lòng đăng bố cục để chúng tôi có thể xem lại. Ngoài ra, điều này có xảy ra với tất cả các phiên bản nền tảng Android không? Hoặc chỉ một số cụ thể –

+0

Sự kiện xảy ra trên tất cả các nền tảng. Tôi đã tạo các thư mục layout trong thư mục màu đỏ như layout-ldpi, layout-mdpi, layout-hdpi và layout-xhdpi và cũng có các thư mục drawable chứa các hình ảnh khác nhau cho các màn hình khác nhau. Ảnh chụp màn hình được chụp từ thiên hà s3 nhưng cũng giống như trên trình giả lập –

+0

Bạn có thể đăng một trong các bố cục đó không? Bạn không cần bố cục khác nhau dựa trên dpi trừ khi bạn có một số trường hợp đặc biệt. –

Trả lời

29

nếu bạn muốn phong cách ban đầu của Ui của bạn để duy trì và thanh tiêu đề phải được loại bỏ với không ảnh hưởng đến điều đó, bạn phải gỡ bỏ các thanh tiêu đề trong hoạt động của bạn chứ không phải là biểu hiện. rời khỏi phong cách chủ đề ban đầu mà bạn đã có trong manifest và trong mỗi hoạt động mà bạn muốn không có thanh tiêu đề sử dụng this.requestWindowFeature(Window.FEATURE_NO_TITLE); trong oncreate() phương pháp trướcsetcontentview() như thế này:

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

tác phẩm này, nhưng đây không phải là giải pháp tốt nhất, thanh tiêu đề nhấp nháy cho một số secod trước khi disapeare – abovesun

+0

thnks it wokred for me..vot lên –

+0

Tôi đã sử dụng chính xác các dòng giống nhau theo thứ tự chính xác này nhưng tôi đã nhận được sự bóc lột: 'android.util.AndroidRuntimeException: requestFeature() phải được gọi trước khi thêm nội dung' - bất kỳ ai biết tại sao? – GyRo

3

Tại sao bạn thay đổi os android inbuilt chủ đề.

Theo hoạt động của bạn yêu cầu bạn phải thực hiện theo cách này

this.requestWindowFeature(Window.FEATURE_NO_TITLE); 

theo @arianoo nói rằng bạn phải sử dụng tính năng này.

Tôi nghĩ đây là cách tốt hơn để ẩn chủ đề thanh tiêu đề.

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

Sẽ là" chính xác hơn "như sau:' requestWindowFeature (android.view.Window.FEATURE_NO_TITLE); " – Reinherd

20

To Hide Action Bar thêm mã dưới đây trong Values ​​/ Styles

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

Sau đó, trong tập tin AndroidManifest.xml của bạn thêm đoạn mã dưới đây vào hoạt động cần thiết

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

" android: windowActionBar "yêu cầu API +11 Vì vậy, kể từ khi khả năng tương thích của tôi là +8," android: windowNoTitle "đã thực hiện mẹo Cảm ơn bạn;) –

7

Trong việc sử dụng tệp kê khai của bạn: -

android:theme="@style/AppTheme" > 

trong styles.xml: -

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

Đáng ngạc nhiên là các công trình này như yo ham muốn, dùng phụ huynh cùng AppBaseTheme trong AppTheme không.

+0

cảm ơn rất nhiều bạn ĐÃ ĐƯỢC ME –

+0

Ngạc nhiên ngạc nhiên, không có gì trên trang này hoạt động cho tôi. Tôi nghi ngờ tôi sẽ ngừng mở rộng 'ActionBarActivity' có lợi cho vani' Activity'. Ngay cả kludges tàn bạo như 'requestWindowFeature (Window.FEATURE_NO_TITLE);' đơn giản là FC. – John

1

sử dụng thẻ ứng dụng của tệp kê khai để xóa thanh tiêu đề cho toàn bộ ứng dụng hoặc đặt thẻ trong thẻ hoạt động để xóa thanh tiêu đề khỏi màn hình hoạt động đơn lẻ.

1

Trong styles.xml của bạn, thay đổi phong cách "AppTheme" như

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