简体   繁体   中英

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>

this is my Style i am calling this Style Like this :

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

my screen come Like this :

在此处输入图片说明

i want set style without Locii Text without Horizontal Line and with white background i am trying to do But unable to do this please suggest me how to Implement this .

Try this style :

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

If you want to remove the tittle you can delete the :

android:label="@string/app_name" 

in your Manifest.xml, or do it by code like :

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

Hope it helps :)

EDIT

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

With code :

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

it seems that you want to create your own layout for your action bar. Here is a way to to it.

In a menu.xml file, create your action bar

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

Then, import it in your others layouts :

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

Don't forget to hide the action bar or to select a theme without action bar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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