我在工具栏的底部实现了边框。如果我没有显示任何菜单项,它看起来很棒。下图显示了我的工具栏的当前外观。我不知道为什么边框在菜单项下很厚。我该如何解决这个问题?
styles.xml
<style name="MyCustomToolBarTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="android:textColorPrimary">@color/Blue</item>
<item name="android:background">@drawable/bottom_border_blue</item>
</style>
app_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_50"
android:minHeight="?android:attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"
app:theme="@style/MyCustomToolBarTheme">
<TextView
android:id="@+id/toolbarTitleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="@dimen/sp_17"
android:textColor="@color/Blue"/>
</android.support.v7.widget.Toolbar>
bottom_border_blue.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item >
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="@color/Blue" />
<solid android:color="@color/White" />
</shape>
</item>
<item android:bottom="1dp">
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="@color/White" />
<solid android:color="#00000000" />
</shape>
</item>
</layer-list>
menu_boat.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<item
android:id="@+id/editButton"
android:orderInCategory="100"
android:title="@string/edit"
android:icon="@drawable/edit"
app:showAsAction="always" />
</menu>
BoatActivity.java
public class BoatActivity extends ActionBarActivity {
private Toolbar toolbar;
private TextView titleTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_boat);
toolbar=(Toolbar)findViewById(R.id.app_bar);
toolbar.setTitle("");
titleTextView=(TextView)toolbar.findViewById(R.id.toolbarTitleTextView);
titleTextView.setText(R.string.myBoat);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
toolbar.setNavigationIcon(R.drawable.ic_back_button);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_boat, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == android.R.id.home) {
finish();
}
return super.onOptionsItemSelected(item);
}
}
答案 0 :(得分:3)
尝试将bottom_border_blue背景设置为xml中工具栏的背景,并检查它是否有效。