2017-11-06 13 views
2

ActionBarに問題があり、その結果、メニューアイコンが画面の端に押し付けられてしまいます。以下は imageAndroidスタジオアクションバーの幅/アイコンの位置

私は微調整してきたスタイルと宣言のいくつかのコードスニペットです:

HomeActivity.xml

private TextView tvViewAll; 
DrawerLayout mDrawerLayout; 
private ActionBarDrawerToggle mDrawerToggle; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_home); 

    //Nav Drawer 
    mDrawerLayout = findViewById(R.id.drawer_layout); 

    //custom shadow for menu drawer 
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); 

    // ActionBarDrawerToggle ties together the the proper interactions 
    // between the sliding drawer and the action bar app icon 
    mDrawerToggle = new ActionBarDrawerToggle (this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close); 

    mDrawerLayout.addDrawerListener(mDrawerToggle); 
    mDrawerToggle.syncState(); 

    getSupportActionBar().setDisplayHomeAsUpEnabled(true); 

} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 

    if(mDrawerToggle.onOptionsItemSelected(item)){ 
     return true; 
    } 

    return super.onOptionsItemSelected(item); 
} 

styles.xml

<resources> 

<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <item name="android:statusBarColor">@color/colorBackgroundBlack</item> 
    <item name="android:navigationBarColor">@color/colorBackgroundBlack</item> 
    <item name="actionMenuTextColor">@color/colorBackgroundBlackDark</item> 
    <item name="colorPrimary">@color/colorBackgroundBlackDark</item> 
    <item name="colorAccent">@color/colorPrimaryDark</item> 
    <item name="colorButtonNormal">@color/ipBlue</item> 
    <item name="toolbarNavigationButtonStyle">@color/ipGreen</item> 
</style> 

<style name="ActionBar.Solid.TMSA.NoTitle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"> 
    <item name="displayOptions">useLogo|showHome</item> 
    <item name="logo">@drawable/ic_ipaustralialogo</item> 
    <item name="android:contentDescription">@string/ip_logo</item> 
</style> 

<style name="AppTheme.TMSA" parent="@style/AppTheme"> 
    <item name="actionBarStyle">@style/ActionBar.Solid.TMSA.NoTitle</item> 
</style> 

ActionBarの書式設定のレイアウトにgovロゴが含まれていない点を覚えていませんが、それ以外の理由でこの斜めのメニューアイコンが表示されないことがわかりません。私はすでにToolbarアプローチをしていると考えられているが、変換する必要がないことを好むだろう

:P

ハッピーコーディング:)

+1

'toolbarNavigationButtonStyle'は、単なる色ではなくスタイルを取ります。私はそれが失敗していると思います。少なくとも、デフォルトスタイルで設定されている最小幅の値を取得していません。そのスタイルを変更する場合は、デフォルトのスタイルを親として独自のスタイルを作成し、その中に目的の属性を設定する必要があります。 [この回答](https://stackoverflow.com/a/46495771)の最初のコードブロックに類似のものが表示されます。 –

+0

問題ありません。Btw、私はあなたがそこに色付けしようとしている部分を正確には分かっていませんが、アニメーション化するハンバーガー・矢印のdrawableはあなた自身も変更できるスタイルを持っています。 [this answer](https://stackoverflow.com/a/27251004)にその例があります。 –

+0

@MikeM。ハンバーガー/矢を微調整したにもかかわらず!私もそれを試してみましょう:)も - あなたを気にして申し訳ありませんが、私は正解としてあなたの1番目のコメントをマークしようとしていますが、私はあなたもupvoteできません - 私は初心者か.. –

答えて

0

ActionBarDrawerToggleActionBarのナビゲーションボタン上のトグルアイコンを設定します。 AppCompatActivityでは、ActionBarは実際にはToolbarの下にあり、そのナビゲーションボタンのスタイルは、toolbarNavigationButtonStyle属性にstyleリソースが設定されています。あなたのテーマで

は、あなたがその属性にcolorのリソースではなく、styleリソースを設定して、デフォルトのスタイルのすべての値は、あなたのトグルがに包まれている理由であるminWidth値、を含む、失われていますdrawableの幅あなたはナビゲーションボタン上のいくつかのスタイル値を変更したい場合は

することは、あなた自身のstyleリソースを作成する必要があり、そのparentとしてデフォルトstyleと、そこに必要な属性を設定して、あなたのテーマのtoolbarNavigationButtonStyleとしてstyleことを指定します。たとえば、次の

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    ... 
    <item name="toolbarNavigationButtonStyle">@style/Toolbar.Button.Navigation</item> 
</style> 

<style name="Toolbar.Button.Navigation" parent="Widget.AppCompat.Toolbar.Button.Navigation"> 
    <item name="android:background">@color/ipGreen</item> 
</style> 

あなたが実際に変更しようとしていることはハンバーガー矢印描画可能であるならば、それはあなたがその中で特定の機能を「サブスタイル」、および変更することができ、独自のスタイルを持っています。たとえば:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    ... 
    <item name="drawerArrowStyle">@style/DrawerArrowToggle</item> 
</style> 

<style name="DrawerArrowToggle" parent="Widget.AppCompat.DrawerArrowToggle"> 
    <item name="color">@color/ipGreen</item> 
</style> 

以下は、そのプロパティの他にカスタマイズする必要があり、 drawerArrowStyleで変更できる属性の完全なリストです。

<!-- The drawing color for the bars --> 
<attr name="color" format="color"/> 
<!-- Whether bars should rotate or not during transition --> 
<attr name="spinBars" format="boolean"/> 
<!-- The total size of the drawable --> 
<attr name="drawableSize" format="dimension"/> 
<!-- The max gap between the bars when they are parallel to each other --> 
<attr name="gapBetweenBars" format="dimension"/> 
<!-- The length of the arrow head when formed to make an arrow --> 
<attr name="arrowHeadLength" format="dimension"/> 
<!-- The length of the shaft when formed to make an arrow --> 
<attr name="arrowShaftLength" format="dimension"/> 
<!-- The length of the bars when they are parallel to each other --> 
<attr name="barLength" format="dimension"/> 
<!-- The thickness (stroke size) for the bar paint --> 
<attr name="thickness" format="dimension"/>