工具栏显示在android中的SearchView左侧

时间:2016-02-10 10:32:58

标签: android toolbar searchview

我想显示Back按钮,但是扭曲的ToolBar会出现在左侧,如下图所示。

demo

 @Override
 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_main, menu);

    MenuItem item = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);

    TextView tv = (TextView) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
    tv.setTextColor(getResources().getColor(android.R.color.white));
    tv.setHintTextColor(getResources().getColor(android.R.color.white));
    tv.setHint(getString(R.string.action_search));

    ImageView imgCloseIcon = (ImageView) searchView.findViewById(android.support.v7.appcompat.R.id.search_close_btn);
    imgCloseIcon.setImageResource(R.drawable.cross_btn);

    searchView.setOnQueryTextListener(this);
}

如何显示后退按钮并隐藏扭曲的ToolBar ??

1 个答案:

答案 0 :(得分:0)

我使用了以下代码,它对我来说很好,

byte[] bytesToSend5 = new byte[] { 0x7E, 0x00, 0x10, 0x17, 0x01, xbee_serienr, 0xFF, 0xFE, 0x02, 0x44, 0x34, 0x04, 0x50 };
serialPort1.Write(bytesToSend5, 0, bytesToSend5.Length);