Android ICS to JB Actionbar tabs changed requirements

陌路散爱 提交于 2019-12-10 12:18:57

问题


I have an application that targets SDK 15, ICS 4.0.3. I just updated it to point at 4.1 it broke my user interface, and makes it pretty ugly:

Here's what it looks like normally on API 15:

And here's it on 16 or 17:

I got a feeling this is because the Nexus 7 uses the phone UI instead of the actual tablet UI... Is there a way to force the tabs into the actionbar without having to use something like ActionBar sherlock or something else (like subclassing)? Or even if I could make the tabs not look terrible, perhaps if they had centered text? Right now the buttons don't even do match_parent. Is there a downside to targeting a lower SDK (I don't need anything higher right now)? My app only runs on ICS or higher.


回答1:


I have created like instagram action bar like a tabs you may check my previous answer and how i did it. Im using phone right im not able to post the code as its on my laptop. Anyway just check my previous answer . Later i will drop by again and post the code.

Edit------

Edit here is the image :). 

back again with a best results :). first thing you need to do is create a layout name it header.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="@dimen/action_bar_height"
    android:layout_gravity="top"
    android:baselineAligned="true"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/share"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="start"
        android:layout_weight=".14"
        android:background="@drawable/action_bar_left_button"
        android:src="@drawable/action_bar_glyph_back" />

    <ImageView
        android:id="@+id/bright"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".14"
        android:background="@drawable/action_bar_left_button"
        android:src="@drawable/action_bar_glyph_lux" />

    <ImageView
        android:id="@+id/rotate"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".14"
        android:background="@drawable/action_bar_left_button"
        android:src="@drawable/rotate" />

    <ImageView
        android:id="@+id/bright"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".14"
        android:background="@drawable/action_bar_left_button"
        android:src="@drawable/action_bar_glyph_lux" />

    <ImageView
        android:id="@+id/rotate"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".14"
        android:background="@drawable/action_bar_left_button"
        android:src="@drawable/rotate" />

    <ImageView
        android:id="@+id/forwa"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".14"
        android:background="@drawable/action_bar_left_button"
        android:src="@drawable/forward" />

</LinearLayout>

after that go to your MainActivity.class and create this method.

    private void setupActionBar() {
    ActionBar actionBar = getActionBar();
    //actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayShowTitleEnabled(false);
    ViewGroup v = (ViewGroup)LayoutInflater.from(this)
        .inflate(R.layout.header, null);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
            ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setCustomView(v,
            new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT,
                    ActionBar.LayoutParams.WRAP_CONTENT,
                    Gravity.CENTER_VERTICAL | Gravity.RIGHT));

} 

add setupActionBar(); to your onCreate Activity and run your app :).

now you have custom ActionBar with Dividers and Images P.S the divider is defined in the layout as an image background :).



来源:https://stackoverflow.com/questions/14658571/android-ics-to-jb-actionbar-tabs-changed-requirements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!