簡體   English   中英

如何在Android中設置自定義操作欄

[英]how to set Custom Action bar in android

   <style name="Sherlock.__Theme" parent="android:Theme.NoTitleBar">
    <item name="android:displayOptions">showHome|homeAsUp|showTitle</item>
    <item name="displayOptions">showHome|homeAsUp|showTitle</item>
    <item name="android:icon">@android:color/transparent</item> 
</style>

這是我的風格,我稱這種風格為:

<application
        android:name="com.lociiapp.LociiApplication"
        android:allowBackup="true"
        android:icon="@drawable/lokii_notification_icon"
        android:theme="@style/Sherlock.__Theme" >

我的屏幕像這樣:

在此處輸入圖片說明

我想在沒有Locii文本且沒有水平線和白色背景的情況下設置樣式,但是我無法做到這一點,請向我建議如何實現此目的。

試試這種風格:

<style name="Sherlock.__Theme" parent="android:Theme.NoTitleBar">
    <!-- Customize your theme here. -->
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:background">#ffffff</item>
</style>

如果要刪除標題,則可以刪除:

android:label="@string/app_name" 

在您的Manifest.xml中,或通過類似以下代碼的方式進行操作:

getSupportActionBar().setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);

希望能幫助到你 :)

編輯

<style name="Sherlock.__Theme" parent="android:Theme.NoTitleBar">
        <!-- Customize your theme here. -->
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:background">#ffffff</item>
        <item name="displayOptions">showHome|useLogo</item>
</style>

帶代碼:

 ActionBar actionBar = getActionBar();
    actionBar.setDisplayShowTitleEnabled(false);

看來您想為自己的操作欄創建自己的布局。 這是一種解決方法。

在menu.xml文件中,創建操作欄

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:background="@color/custom"
    android:gravity="center_vertical">

 ...
</LinearLayout>

然后,將其導入您的其他布局中:

<include
    android:id="@+id/menu"
    layout="@layout/menu" />

不要忘記隱藏操作欄或選擇沒有操作欄的主題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM