Java tutorial
/* Swisscom Safe Connect Copyright (C) 2014 Swisscom This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.swisscom.safeconnect.activity; import android.app.ActionBar; import android.app.Activity; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.view.View; import android.widget.ImageView; import android.widget.TextView; import com.swisscom.safeconnect.R; import com.swisscom.safeconnect.utils.Config; import com.swisscom.safeconnect.utils.Fonts; /** * Created by vadim on 18.09.14. */ public class PipeActivity extends FragmentActivity { protected TextView tvTitle; private ImageView imgBackBtn; private View actionBarView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Fonts.init(this); Config.getInstance().init(this); initActionBar(this, 0, null); } protected void initActionBar(Activity activity, int stringId, View.OnClickListener listener) { ActionBar ab = activity.getActionBar(); //Tutorial with NoTitle Theme returns null here if (ab == null) { return; } ab.setDisplayShowCustomEnabled(true); ab.setDisplayShowTitleEnabled(false); ab.setDisplayShowHomeEnabled(false); actionBarView = activity.getLayoutInflater().inflate(R.layout.actionbar, null); tvTitle = (TextView) actionBarView.findViewById(R.id.tv_title); imgBackBtn = (ImageView) actionBarView.findViewById(R.id.img_back_btn); if (tvTitle != null && stringId != 0) { tvTitle.setText(stringId); } setOnBackPressedListener(listener); ab.setCustomView(actionBarView); } protected void initActionBar(Activity activity, int stringId, boolean homeAsUpEnabled) { if (homeAsUpEnabled) { initActionBar(activity, stringId, new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); } else { initActionBar(activity, stringId, null); } } protected void setOnBackPressedListener(View.OnClickListener listener) { if (listener != null) { actionBarView.setOnClickListener(listener); imgBackBtn.setVisibility(View.VISIBLE); } else { imgBackBtn.setVisibility(View.GONE); actionBarView.setOnClickListener(null); } } }