Domanda

am creating an app using sherlock actionbar.. here i want to inflate my custom title_background...

this is what i need....... enter image description here

this is my title_background_layout

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:gravity="center"
android:paddingLeft="5dip"
android:background="@drawable/titlebar">

<ImageView
    android:id="@+id/header"
    android:src="@drawable/netmd"
    android:layout_width="140dp"
    android:layout_height="40dp"/>

and i set the tittle background in my main activity....

public class MainActivity extends SherlockActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);      
    setContentView(R.layout.activity_main);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_background);      
}

but some error shows in logcat.

 05-02 10:17:36.302: E/AndroidRuntime(706): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.netmdapp1/com.example.netmdapp1.MainActivity}:

android.util.AndroidRuntimeException: You cannot combine custom titles with other title features

enter image description here

after editing my code

i find out another solution bye creating my own style...

my style xml file is....

<style name="CustomActioBar" parent="Widget.Sherlock.ActionBar">
        <item name="android:background">@drawable/titlebar</item>
        <item name="background">@drawable/titlebar</item>
    </style>
    <!-- Application theme. -->

    <style name="AppTheme" parent="Theme.Sherlock.Light">
        <item name="actionBarStyle">@style/CustomActioBar</item>


    </style>

but it works only in android version 2.3.3 it doesnt works in higher versions.

no its not working in my mobile also.......

enter image description here

È stato utile?

Soluzione

If you want to set CustomView for sherlock actionbar follow this code

final ActionBar ab = getSupportActionBar();        
ab.setDisplayShowCustomEnabled(true);

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.title_background, null);
ab.setCustomView(view);

EDIT : if you don't want to show logo and title just add these params along with above code for action bar

ab.setDisplayHomeAsUpEnabled(false);
ab.setDisplayShowHomeEnabled(false);
ab.setDisplayShowTitleEnabled(false);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top