The red rectangle (The bar with the title of the activity) it is what I want to remove (see the picture):
http://subefotos.com/ver/?8e6468bdbc19b0864d5090fa79e54120o.jpg
What I have in my code:
public class HomeActivity extends ActionBarActivity implements ActionBar.TabListener, OnItemSelectedListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_ACTION_BAR);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_home);
// Set up the action bar.
final ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(false);
actionBar.setDisplayUseLogoEnabled(false);
} }
I can remove all the bar, including the HOME-STATISTIC-CLASSIFICATION, but I don't want to remove this.
I think that what I want to do it is impossible if we take into account this link: http://developer.android.com/guide/topics/ui/actionbar.html
Although if somebody knows how can be done, please post it.
Thank you for your time.
Related
I have a generic
MyActivity extends AppCompatActivity
I don't override the toolbar with a custom xml defined toolbar, just use the generated one Android provides.
I can set the title via your normal
getSupportActionBar().setTitle("foo");
but setting the subtitle via
getSupportActionBar().setSubtitle("bar");
doesn't set it. It remains blank. I'm doing this onCreate()
(I feel I've done this many times before with no fail)
Although I've noticed if I visit another activity, then return, the subtitle would then show... not on orientation change, not on recreate() but only when I'm returning from an activity.
I'm experiencing this on 5.0 and 7.0
For the time being I'll likely define my own Toolbar and move forward since that seems where most people have solutions for this same problem.
Relevant code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_replenishment_list);
ButterKnife.bind(this);
MyApplication.getInstance().getComponent().inject(this);
setupUI();
}
private void setupUI() {
setupActionBar();
}
private void setupActionBar() {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
//TODO: not working unless activity is recreated...
// explore custom xml defined toolbar
//actionBar.setTitle("different title than what is defined in manifest"); <-- this does work, but not this
actionBar.setSubtitle(UserUtil.getFormattedFirstNameLastName(userService.getUserFromJWT(), this));
}
}
I have put the below code in my onCreate() method.
ActionBar actionBar = getActionBar();
if (actionBar==null) {
System.out.println("TEST NULL");
} else {
System.out.println("TEST NOT NULL");
}
The result is null. When I add the toolbar first it works fine.
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getActionBar();
actionBar.setSubtitle("TESTING");
Your getSupportActionBar or getActionBar will return null if you didn't set toolbar to it. You need to set the toolbar to your action bar before using getSupportActionBar or getActionBar.
I am the android developer (freshers).
Here is my java code. where I have tried TabSpec.addTab(.......) but it gives me error of nullpointerexception. plz let me know what should I do? please provide me the code for tabhost with xml and java...thank you.
public class HomeActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Toolbar toolbar = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(null);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}
Is this the error where I use supportactionbar methods?
please help me I want to use these tabs with the listview and searchview..
thank you.
Hello I am using Sherlock library to achieve the Tabs. Here I am looking to remove the ActionBar at the top and set the custom title layout instead of it.
I achieved a functionality to add the Tabs but could not set the custom title over ActionBar. Any way to do this ?
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pay_stub);
// adding action bar tabs to the activity
ActionBar mActionBar = getSupportActionBar();
Tab firstTab = mActionBar.newTab().setText(getString(R.string.paystub_current_tab)).setTabListener(this);
Tab secondTab = mActionBar.newTab().setText(getString(R.string.paystub_all_tab)).setTabListener(this);
// add the tabs to the action bar
mActionBar.addTab(firstTab);
mActionBar.addTab(secondTab);
// set the navigation mode the Action Bar Tabs
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
}
Thanks in advance.
I resolved this by adding background color and icon of the ActionBar.
ActionBar actionBar = getSupportActionBar();
setTitle("");
actionBar.setIcon(R.drawable.headerlogo);
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#F4A401")));
I'm using the AppCompat/ActionBarCompat library and I need to create a custom ActionBar. I need to open the activity without an ActionBar and enable it only when I add the custom view. How can I do this?
PS: I need to define the activity to not use an ActionBar through the AndroidManifest.xml and my application minimum API level is 10.
.hide() the action bar and then .show() the action bar when your ready for it
import android.support.v7.app.ActionBar;
...
private ActionBar mActionbar;
...
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mActionbar = getSupportActionBar();
mActionbar.hide()
}
...
somewhere when something cool happens
mActionbar.show();
I am making a action bar using sherlock action bar but it is not shown when i run it.This is the code:
public class NaseebactionbarActivity extends SherlockActivity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ActionBar actionbar = getSupportActionBar();
actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab PlayerTab = actionbar.newTab().setText("Fragment A");
ActionBar.Tab StationsTab = actionbar.newTab().setText("Fragment B");
actionbar.addTab(PlayerTab);
actionbar.addTab(StationsTab);
actionbar.show();
}
please tell me what is the problem and how to solve it.
Extend your Activity from SherlockFragmentActivity instead of SherlockActivity:
public class MyActivity extends SherlockFragmentActivity {
// ...
}
In your AndroidManifest, be sure to set the theme of your application to :
android:theme="#style/Theme.Sherlock"