2015-07-28 44 views
6

Làm cách nào để thay đổi kích thước của một mục menu trong thanh công cụ Android? Hiện tại các menu có kích thước rất nhỏ và tôi muốn tăng kích thước. Nếu có ai biết hãy giúp tôi tìm một giải pháp.Làm thế nào để thay đổi kích thước biểu tượng mục trình đơn trên cùng của thanh công cụ android

app_bar.xml

<?xml version="1.0" encoding="utf-8"?> 
    <android.support.v7.widget.Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/primaryColor" 
    android:minHeight="?attr/actionBarSize" 
    android:paddingTop="@dimen/app_bar_top_padding" 
    android:theme="@style/ToolBarStyle"/> 

Styles.xml

<resources xmlns:android="http://schemas.android.com/apk/res/android"> 
<style name="AppTheme" parent="AppTheme.Base"> </style> 
<!-- Application theme. --> 
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar"> 
    <item name="colorPrimary">@color/primaryColor</item> 
    <item name="colorPrimaryDark">@color/primaryColorDark</item> 
    <item name="colorAccent">@color/accentColor</item> 
    <item name="colorControlHighlight">@color/primary_high_light</item> 
    <!-- <item name="textColorPrimary">@color/ColorPrimaryText</item> --> 
</style> 

<style name="ToolBarStyle" parent="ThemeOverlay.AppCompat.Dark"> 
    <item name="android:textColorPrimary">#ffffff</item> 

</style> 
<style name="option" parent="Theme.AppCompat.Light"> 
</style> 
<style name="Dialog" parent="Base.Theme.AppCompat.Light.Dialog"> 
</style> 

menu_option.xml

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto"> 


<item android:id="@+id/homes" 
    android:title="homes" 
    android:icon="@drawable/ic_action_home1" 
    app:showAsAction="always"/> 

<item android:id="@+id/profilepreview" 
    android:title="ProfilePreview" 
    android:icon="@drawable/profile" 
    app:showAsAction="always"/> 

<item android:id="@+id/findPeople" 
    android:title="findPeople" 
    android:icon="@drawable/ic_action_search1" 
    app:showAsAction="always"/> 

<item android:id="@+id/log" 
    android:title="log" 
    android:icon="@drawable/ic_action_logout1" 
    app:showAsAction="always"/> 

</menu> 

MainActivity.java

public boolean onCreateOptionsMenu(Menu menu) { 
    MenuInflater inflater = getMenuInflater(); 
    inflater.inflate(R.menu.menu_option, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    switch (item.getItemId()) { 

      case R.id.profilepreview: 
      startActivity(new Intent(this, ProfilePreview.class)); 
      return true; 

      case R.id.homes: 
      mFragment = new HomeFragment(); 
      break; 

      case R.id.findPeople: 
      mFragment = new FindFriendsFragment(); 
      break; 

      case R.id.log: 
      M.logOut(this); 
      mIntent = new Intent(this, LoginActivity.class); 
      finish(); 

    } 

    if (mFragment != null && mIntent == null) { 
     mFragmentManager = getFragmentManager(); 
     mFragmentManager.beginTransaction() 
       .replace(R.id.frameContainer, mFragment).commit(); 
    } else { 
     startActivity(mIntent); 
     mIntent = null; 
    }return super.onOptionsItemSelected(item); 
    } 
+0

http://www.android4devs.com/2014/12/how-to-make-material-design-app.html – arodriguezdonaire

+0

tôi đã thử hướng dẫn đó, nhưng không có tùy chọn nào cho kích thước thay đổi của các biểu tượng trình đơn đó –

+1

@PrinsPrem Tôi đã gặp vấn đề tương tự với kích thước biểu tượng bên trong thanh công cụ. Bạn muốn biết nếu bạn tìm thấy bất kỳ giải pháp cho vấn đề này? Cảm ơn trước. – Amin

Trả lời

0

Tôi cũng gặp phải vấn đề này và giải pháp duy nhất tôi có thể có là sử dụng các hình ảnh nhỏ hơn. Kích thước 24dp từ các biểu tượng ở đây (https://design.google.com/icons) vừa với thanh công cụ của tôi.

0

Bạn có thể thiết kế bố cục tùy chỉnh và thêm bố cục làm hành động của bạn. Đồng thời đảm bảo bạn không thêm bất kỳ biểu tượng nào trong tệp menu.xml.

<item android:id="@+id/homes" 
android:title="homes" 
app:actionLayout="@layout/your_custom_layout" 
app:showAsAction="always"/> 

Sau đó, cho min_height vào bố cục tùy chỉnh của bạn.

Các vấn đề liên quan