如何修复似乎在nexus设备中移位的导航栏?

时间:2014-01-22 14:42:38

标签: android android-layout android-fragments android-actionbar

我的应用顶部有一个导航栏。如果galaxy / htc设备如下: enter image description here 但是,在nexus设备中,它似乎有一点如下变化,不确定原因:

enter image description here 这是我的相同代码:(actionbar.xml):

   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:foo="http://schemas.android.com/apk/res/com.justin.abc"
        android:id="@+id/title_information_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#27272b"
        android:fillViewport="true" >

        <com.justin.abc.utils.FontTextView
            android:id="@+id/actionbar_title"
            android:layout_width="wrap_content"
            android:layout_height="@dimen/actionbar_title_height"
            android:layout_marginTop="@dimen/actionbar_title_topmargin"
            android:layout_marginLeft="@dimen/common_left_padding"
            android:text="@string/title_about"
            foo:customFont="proxima-nova-regular-Regular.ttf"


            android:textColor="@color/white"
            android:textSize="@dimen/actionbar_title" />

        <Button
            android:id="@+id/button_done"
            android:layout_width="wrap_content"
            android:layout_height="@dimen/done_button_height"
            android:layout_marginTop="@dimen/done_button_topmargin"
            android:layout_alignParentRight="true"
            android:layout_marginLeft="@dimen/done_button_leftmargin"
            android:layout_marginRight="@dimen/done_button_rightmargin"
            android:background="@drawable/done_cancel_button"
            android:text="@string/menu_done"
            android:textColor="@drawable/done_button_text"
            android:textSize="@dimen/button_text" />


        <View
            android:layout_width="wrap_content"
            android:layout_height="2dp"
            android:layout_marginTop="@dimen/actionbar_view_margintop"
            android:background="@color/black"
            android:visibility="visible" />

    </RelativeLayout>

我是如何修复相同的线索所以它适用于所有设备?谢谢!

这是相关的主题:

<style name="AppTheme" parent="@style/Theme.Sherlock"></style>

<style name="AppTheme.NoActionBar" parent="@style/Theme.Sherlock.NoActionBar"></style>

<style name="AppBaseTheme.NoActionBar" parent="AppTheme.NoActionBar"></style>

<!-- Although this is doing exactly what AppBaseTheme is doing,
    it fixes the initialization display of the icon being truncated -->
 <style name="ABTheme"  parent="AppTheme">
    <item name="homeAsUpIndicator">@null</item>
    <item name="selectableItemBackground">@drawable/btn_selector_home_icon</item>
</style>

<style name="AppBaseTheme" parent="AppTheme">
    <item name="homeAsUpIndicator">@null</item>
    <item name="selectableItemBackground">@drawable/btn_selector_home_icon</item>
    <item name="android:listViewStyle">@style/ListViewAppTheme</item>

    <item name="android:listViewWhiteStyle">@style/ListViewAppTheme.White</item>

    <item name="android:spinnerItemStyle">@style/SpinnerItemAppTheme</item>
</style>

<style name="ListViewAppTheme" parent="android:Widget.ListView">
    <item name="android:listSelector">@drawable/list_selector_holo_light</item>
</style>

<style name="ListViewAppTheme.White" parent="android:Widget.ListView.White">
    <item name="android:listSelector">@drawable/list_selector_holo_light</item>
</style>

<style name="SpinnerItemAppTheme" parent="android:TextAppearance.Widget.TextView.SpinnerItem">
    <item name="android:textColor">#000000</item>
</style>
<style name="abc.TextView" parent="android:Widget.Holo.TextView"></style>

<style name="T1UserContactCountry">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textColor">#cccccc</item>
    <item name="android:textSize">@dimen/title</item>
    <item name="android:paddingLeft">@dimen/common_left_padding</item>
    <item name="android:layout_gravity">left</item>
</style>
<style name="T1UserContactPhone">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textColor">@color/abs__holo_blue_light</item>
    <item name="android:textSize">@dimen/title</item>
    <item name="android:onClick">onPhoneNumberClicked</item>
    <item name="android:paddingRight">@dimen/common_right_padding</item>
    <item name="android:layout_gravity">right</item>
    <item name="android:clickable">true</item>
</style>
<style name="T1TableRowSeparator">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:paddingTop">10dp</item>
    <item name="android:paddingBottom">10dp</item>
</style>
<style name="T1ViewSeparator">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">2dp</item>
    <item name="android:background">@color/header_grey</item>
    <item name="android:layout_span">2</item>
</style>

<style name="abc.TextView.ListsTextView">
    <item name="android:ellipsize">end</item>
    <item name="android:gravity">right</item>
    <item name="android:singleLine">true</item>
    <item name="android:background">@android:color/transparent</item>
</style>

<style name="abc.TextView.ListsTextView.Header">
    <item name="android:paddingTop">2dp</item>
    <item name="android:textSize">15sp</item>
    <item name="android:background">@android:color/transparent</item>
</style>
<style name="CustomTheme">
   <item name="android:windowBackground">@color/custom_theme_color</item>
<item name="android:colorBackground">@color/custom_theme_color</item>
</style>
<style name="abc.TextView.ListsTextView.Value">
    <item name="android:textSize">15sp</item>
    <item name="android:background">@android:color/transparent</item>
</style>

<style name="abc.TextView.NavigationItem">
    <item name="android:clickable">true</item>
    <item name="android:padding">3dp</item>
    <item name="android:textSize">20sp</item>
    <item name="android:background">@color/black</item>
</style>

<style name="search_autosuggest_header" parent="android:Widget.Holo.TextView">
    <item name="android:paddingBottom">5dp</item>
    <item name="android:paddingLeft">3dp</item>
    <item name="android:textSize">16sp</item>
    <item name="android:textColor">@color/search_autosuggest_header_text</item>
    <item name="android:background">@drawable/background_search_auto_suggest_header</item>
    <item name="android:textStyle">bold</item>
</style>

<style name="abc.TextView.Preferences">
    <item name="android:padding">8dp</item>
</style>

<style name="abc.TextView.Preferences.Title">
    <item name="android:background">@color/black</item>
    <item name="android:textColor">@color/background_preferences_item</item>
</style>

<style name="abc.TextView.Preferences.Item">
    <item name="android:background">@color/background_preferences_item</item>
    <item name="android:textColor">@color/background_preferences_title</item>
</style>

<style name="abc.TextView.Preferences.Item.clickable">
    <item name="android:background">@drawable/background_preferences_layout_selector</item>
    <item name="android:textColor">@color/background_preferences_title</item>
</style>

<style name="abc.Button.Toggle" parent="android:Widget.Holo.Button.Toggle">
    <item name="android:button">@null</item>
    <item name="android:textOff"></item>
    <item name="android:textOn"></item>
    <item name="android:background">@drawable/toggle_selector_abc</item>
</style>

<style name="LoginEditText" parent="@android:style/Widget.EditText">
    <item name="@android:textColor">@color/textbox_hint</item>
    <item name="@android:textSize">16sp</item>
    <item name="@android:maxLines">1</item>
    <item name="@android:fontFamily">Roboto-Regular</item>
</style>

 <style name="MenuDialogAnimation">
     <item name="android:windowEnterAnimation">@anim/grow_from_topright_to_bottomleft</item>
     <item name="android:windowExitAnimation">@anim/shrink_from_bottomleft_to_topright</item>
 </style>

 <style name="MenuDialogAnimationLeft">
     <item name="android:windowEnterAnimation">@anim/grow_from_topleft_to_bottomright</item>
     <item name="android:windowExitAnimation">@anim/shrink_from_bottomright_to_topleft</item>
 </style>

 <style name="BriefcaseMenuDialogAnimation">
     <item name="android:windowEnterAnimation">@android:anim/fade_in</item>
     <item name="android:windowExitAnimation">@android:anim/fade_out</item>
 </style>
 <style name="ButtonText">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textColor">#ffffff</item>
    <item name="android:gravity">center</item>
    <item name="android:layout_margin">3dp</item>
    <item name="android:textSize">30dp</item>
    <item name="android:shadowColor">#000000</item>
    <item name="android:shadowDx">1</item>
    <item name="android:shadowDy">1</item>
    <item name="android:shadowRadius">2</item>
    <item name="android:paddingLeft">15dp</item>
    <item name="android:paddingRight">15dp</item>
</style>
<style name="Divider">
     <item name="android:divider">@drawable/divider</item>
     <item name="android:dividerHeight">1px</item>

</style>

<style name="related_buttons" parent="android:Widget.Holo.TextView">
    <item name="android:clickable">true</item>
    <item name="android:gravity">center_vertical|left</item>
    <item name="android:layout_marginBottom">3dp</item>
    <item name="android:layout_marginTop">3dp</item>
    <item name="android:paddingLeft">12dp</item>
    <item name="android:paddingRight">12dp</item>
    <item name="android:visibility">gone</item>
    <item name="android:drawableRight">@drawable/arrow_chevron_selector</item>
</style>

在我的清单中,我引用如下:

 <application
        android:name=".abcApplication"
        android:allowBackup="true"
        android:icon="@drawable/abc_launcher"
        android:label="@string/app_long_name"
        android:theme="@style/ABTheme" android:debuggable="false">

这是我的java代码:

public void manageActionBar() {
        final ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setCustomView(R.layout.actionbar_no_button);
        getSupportActionBar().setDisplayShowHomeEnabled(false);
        final TextView titleView = (TextView) actionBar.getCustomView().findViewById(R.id.actionbar_title);
        titleView.setText(R.string.personal);
    }

2 个答案:

答案 0 :(得分:3)

这不起作用的原因是因为这不是您自定义Action Bar的方式,我建议您阅读有关如何自定义Action Bar here的内容。
您要做的基本上是为您的应用程序定义theme,正如您在评论中所述,您希望根据项目要求更改外观。

以下是我上面链接的文章中的示例:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
           parent="@style/Theme.AppCompat.Light">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
        <item name="android:actionBarTabTextStyle">@style/TabTextStyle</item>
        <item name="android:actionMenuTextColor">@color/actionbar_text</item>

        <!-- Support library compatibility -->
        <item name="actionBarStyle">@style/MyActionBar</item>
        <item name="actionBarTabTextStyle">@style/TabTextStyle</item>
        <item name="actionMenuTextColor">@color/actionbar_text</item>
    </style>

    <!-- general styles for the action bar -->
    <style name="MyActionBar"
           parent="@style/Widget.AppCompat.ActionBar">
        <item name="android:titleTextStyle">@style/TitleTextStyle</item>
        <item name="android:background">@drawable/actionbar_background</item>
        <item name="android:backgroundStacked">@drawable/actionbar_background</item>
        <item name="android:backgroundSplit">@drawable/actionbar_background</item>

        <!-- Support library compatibility -->
        <item name="titleTextStyle">@style/TitleTextStyle</item>
        <item name="background">@drawable/actionbar_background</item>
        <item name="backgroundStacked">@drawable/actionbar_background</item>
        <item name="backgroundSplit">@drawable/actionbar_background</item>
    </style>

    <!-- action bar title text -->
    <style name="TitleTextStyle"
           parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">@color/actionbar_text</item>
    </style>

    <!-- action bar tab text -->
    <style name="TabTextStyle"
           parent="@style/Widget.AppCompat.ActionBar.TabText">
        <item name="android:textColor">@color/actionbar_text</item>
    </style>
</resources>

完成此操作后,您可以自定义Action Bar的外观,使其看起来与您想要的一样(确保以正确的方式设置颜色)。

答案 1 :(得分:0)

我也遇到了ActionBar的问题。问题只出现在Nexus 7上(我没有其他Nexus)。我将自定义视图放在操作栏中,以完全覆盖它(因为它无法按照我想要的方式配置)。

LayoutParams layout = new LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT );
LayoutInflater inflator = (LayoutInflater) getSystemService( Context.LAYOUT_INFLATER_SERVICE );
View v = inflator.inflate( R.layout.my_actionbar_layout, null );
getActionBar().setDisplayShowCustomEnabled( true );
getActionBar().setDisplayShowHomeEnabled( false );
getActionBar().setCustomView( v, layout );

但是,左侧尺寸存在间隙,并且视图在屏幕右边缘上走得太远。

然而,解决方案非常简单:

getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

希望这能帮到你(和其他人)。

现金: 我从这个页面找到了答案: http://answer.techwikihow.com/1352928/actionbar-customview-extra-padding-cannot-removed.html