2017-11-06 18 views
2

ActionBar에 문제가있어서 내 메뉴 아이콘이 화면 가장자리에 밀려납니다!Android Studio ActionBar 너비/아이콘 위치

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> 

: 아래 image

내가 쥐게 한 스타일의 몇 가지 코드 조각과 선언이다 의 서식 레이아웃을 gov 로고가 포함 된 것을 제외하고는 기억하지 못했지만이 비스듬한 메뉴 아이콘이 나타나는 이유를 알아낼 수 없습니다. 나는 이미 Toolbar 접근을하고 생각했지만 변환해야하지 선호

: P

해피 코딩 :)

+1

'toolbarNavigationButtonStyle'은 색상이 아닌 스타일을 취합니다. 나는 그것이 그것으로 실패하고 있다고 생각할 것이다. 최소한 기본 스타일로 설정된 최소 너비 값을 가져 오지 못합니다. 이 스타일을 수정하려면 기본 스타일을 부모로 사용하여 자신 만의 스타일을 만들어야하고 원하는 속성을 설정해야합니다. 이 코드는 [이 답변] (https://stackoverflow.com/a/46495771)의 첫 번째 코드 블록에 표시됩니다. –

+0

문제 없습니다.Btw, 정확히 어떤 부분을 색칠하려고하는지 모르겠지만 움직이는 햄버그 화살표 드로어 블은 수정할 수있는 스타일이 있습니다. [이 답변] (https://stackoverflow.com/a/27251004)에 그 예가 있습니다. –

+0

@MikeM. 햄버거/화살을 조정하는 것조차하지 않았다! 나는 그것을 시도해 줄 것이다 :) 또한 - 당신을 귀찮게해서 미안하지만, 나는 정답으로 당신의 1 번째 코멘트를 표시하려고 노력하고있다. 그러나 나는 심지어 당신을 업 - 포워드 할 수 없다 - 나는 초보자이거나 ..이기 때문에? –

답변

0

ActionBarDrawerToggleActionBar의 네비게이션 버튼의 토글 아이콘을 설정합니다. AppCompatActivity에서 ActionBar은 실제로는 Toolbar 아래에 있으며 해당 탐색 버튼의 테마는 toolbarNavigationButtonStyle 속성에 설정된 style 리소스로 지정됩니다.

테마에

, 당신은 오히려 style 자원보다, 그 속성에 color 자원을 설정했으며, 기본 스타일의 모든 값은 왜 전환이에 싸여있는 minWidth 값을 포함하여, 손실 drawable의 폭 당신이 탐색 버튼을 몇 가지 스타일의 값을 수정하려면

, 당신은 당신의 테마의 toolbarNavigationButtonStylestyle 것을, 그 parent으로 기본 style로, 자신의 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"/>