0
我需要導航到我之前的活動。我想使用動作欄(工具欄)的箭頭。我無法看到我的動作欄(工具欄)中的向上箭頭。我附上下面的活動代碼。爲什麼我無法看到操作欄中的向上箭頭?
ImageActivity.java
public class ImageActivity extends AppCompatActivity {
private Toolbar toolbar;
int img,img1;
String text;
ImageView imgicon;
@Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().show();
Drawable upArrow = ContextCompat.getDrawable(this, R.drawable.abc_ic_ab_back_mtrl_am_alpha);
upArrow.setColorFilter(ContextCompat.getColor(this, R.color.white), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(upArrow);
getSupportActionBar().setHomeButtonEnabled(true);
imgicon = (ImageView) findViewById(R.id.img);
Bundle bundle = getIntent().getExtras();
if(bundle!=null)
{
img = bundle.getInt("img");
text = bundle.getString("Phone");
getSupportActionBar().setTitle("text");
imgicon.setImageResource(img);
}
img1 = bundle.getInt("img1");
imgicon.setImageResource(img1);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
//Write your logic here
this.finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
有沒有人遇到這種情況,不知怎麼找到了一種方法來解決呢?提前致謝。
我想你的答案用這個,但它是不工作的建議...謝謝。 – Srikanth86in
@ Srikanth86它將工作絕對好,但請檢查您的口音顏色和原色,有時它也啓用但已合併爲背景顏色 –