質問

I use ActionbarActivity from the support library offered by Google. I made a custom view for my actionbar contain button and image attached to the right side. the problem is once the activity starts I see the default title of the actionbar (app name) and the android launcher icon (even not my launcher icon) appears on left side for a while and then my custom view applied. How can I solve this issue. I called the following code after and before onCreateView() with no luck. I also have another problem that it keeps its icon with android logo icon not my launcher icon even after my custom view is set.

this.getSupportActionBar().setDisplayShowCustomEnabled(true);
this.getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayShowHomeEnabled(false);
LayoutInflater inflator = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View v = inflator.inflate(R.layout.title_view, null);
TextView tvTitle = (TextView) v.findViewById(R.id.actionbar_title);
    this.getSupportActionBar().setCustomView(v);

Edit 1: The problem of the icon was solved. I was adding the support library as separate project. Apparently the launcher icon in the support library replaced my launcher icon. I removed all resources from the support library project and now my icon appears normally. Of course the main problem still there.

役に立ちましたか?

解決

Well, I did some work around for this

I changed the style of the actionbar I made to have transparent icon and text

<style name="MyTheme" parent="@style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
</style>


<style name="MyTheme.ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
    <item name="android:icon">@android:color/transparent</item>
    <item name="android:background">@drawable/actionbar_bg</item>
</style>

<style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">@android:color/transparent</item>
</style>

2- Then in setupActionBar() method I set the color back manually

private void setupActionBar() {
        getSupportActionBar().setDisplayShowHomeEnabled(false);
        this.getSupportActionBar().setDisplayShowTitleEnabled(false);
        this.getSupportActionBar().setDisplayShowCustomEnabled(true);


    LayoutInflater inflator = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflator.inflate(R.layout.title_view, null);
    TextView tvTitle = (TextView) v.findViewById(R.id.actionbar_title);
        tvTitle.setTextColor(getResources().getColor(R.color.white));
....
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top