I have just started working on a new tabbed App.
For some reason, I can't seem to be able to get rid for a settings action item with its own bar that goes below my tab bar.
Anyone know what this is all about?
public class MainActivity extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Fragment fragment = new Fragment();
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
ActionBar.Tab mapTab = actionBar.newTab().setText("TEST1");
ActionBar.Tab infoTab = actionBar.newTab().setText("TEST2");
ActionBar.Tab settingsTab = actionBar.newTab().setText("TEST3");
mapTab.setTabListener(new TabListener(fragment));
infoTab.setTabListener(new TabListener(fragment));
settingsTab.setTabListener(new TabListener(fragment));
actionBar.addTab(mapTab, 0, false);
actionBar.addTab(infoTab, 1, false);
actionBar.addTab(settingsTab, 2, false);
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.nfcproducttracing"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="com.example.nfcproducttracing.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Presumably, you are adding that action item in onCreateOptionsMenu() of your activity. If you do not want that action item, remove it.
Related
I have added tab navigation within a tooleap popout, but because the way tooleap works the tabs are covering the toolbar which is required for tooleap to be used. I would like to move the tabs to the bottom of the screen to avoid this issue.
This is what it currently looks like:
This is want I want it to look like:
This is my Tooleap activity I want the tabs in:
import android.os.Bundle;
import com.tooleap.sdk.TooleapActivities;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBar.Tab;
import android.util.Log;
public class MyTooleapActivity extends TooleapActivities.ActionBarActivity {
private static final String TAG = "junk";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_container);
setUpTabs(savedInstanceState);
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// save the selected tab's index so it's re-selected on orientation change
outState.putInt("tabIndex", getSupportActionBar().getSelectedNavigationIndex());
}
private void setUpTabs(Bundle savedInstanceState) {
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(actionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowTitleEnabled(false);
Tab tab_one = actionBar.newTab();
Tab tab_two = actionBar.newTab();
Tab tab_three = actionBar.newTab();
FirstFragment firstFragment = new FirstFragment();
tab_one.setText("One")
.setContentDescription("The first tab")
.setTabListener(
new MyTabListener<FirstFragment>(
firstFragment));
SecondFragment secondFragment = new SecondFragment();
tab_two.setText("Two")
.setContentDescription("The second tab")
.setTabListener(
new MyTabListener<SecondFragment>(
secondFragment));
ThirdFragment thirdFragment = new ThirdFragment();
tab_three
.setText("Three")
.setContentDescription("The third tab")
.setTabListener(
new MyTabListener<ThirdFragment>(
thirdFragment));
actionBar.addTab(tab_one);
actionBar.addTab(tab_two);
actionBar.addTab(tab_three);
if (savedInstanceState != null) {
Log.i(TAG, "setting selected tab from saved bundle");
// get the saved selected tab's index and set that tab as selected
actionBar.setSelectedNavigationItem(savedInstanceState.getInt("tabIndex", 0));
}
}
}
and here is my activity_container.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</FrameLayout>
</LinearLayout>
Manifest.xml as requested:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name=".MyActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MyTooleapActivity"
android:launchMode="singleInstance"
android:taskAffinity=".tooleap"
android:theme="#style/Theme.AppCompat.Translucent">
<intent-filter>
<action android:name="com.tooleap.sdk.TOOLEAP_SHOW" />
</intent-filter>
</activity>
<service android:name="com.tooleap.sdk.TooleapAppService" />
<service
android:name="com.tooleap.sdk.TooleapUIService"
android:exported="true"
android:process=":UIService">
<intent-filter>
<action android:name="com.tooleap.sdk.BIND_UI_SERVICE" />
</intent-filter>
</service>
<receiver android:name="com.tooleap.sdk.TooleapReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package" />
</intent-filter>
<intent-filter>
<action android:name="com.tooleap.sdk.TOOLEAP_ACTION" />
</intent-filter>
</receiver>
<meta-data
android:name="com.tooleap.sdk.apiKey"
android:value="Placeholder" />
<activity android:name=".UserBuilding"></activity>
</application>
</manifest>
I have really tried everything I found on the internet and cannot find a solution.
I want to remove title bar from all of my activities, and my main activity to look like home activity screen on facebook. So, action bar with swiping, fragments and a search on the top. Iv done action bar with swiping and fragments right, but I cannot remove title bar for my search. Here is the code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.activity_main);
initializeLayout();
}
public Lokal getLokal() {
return lokal;
}
public Context context(){
return getApplicationContext();
}
private void initializeLayout(){
// Initilization
viewPager = (ViewPager) findViewById(R.id.pager);
actionBar = getActionBar();
mAdapter = new TabsPageAdapter(getSupportFragmentManager());
getActionBar().setDisplayShowTitleEnabled(false);
getActionBar().setDisplayShowHomeEnabled(false);
viewPager.setAdapter(mAdapter);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Adding Tabs
for (String tab_name : tabs) {
actionBar.addTab(actionBar.newTab().setText(tab_name)
.setTabListener(this));
}
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageSelected(int position) {
// on changing the page
// make respected tab selected
actionBar.setSelectedNavigationItem(position);
}
#Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
#Override
public void onPageScrollStateChanged(int arg0) {
}
});
}
And here is my manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="v.menadzeri" >
<uses-sdk android:minSdkVersion="11" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:theme="#style/Theme.Sherlock.Light.NoActionBar">
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id"/>
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
<activity
android:name=".activities.Login"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activities.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MainActiviy" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".activities.SplashScreen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SplashScreen" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".activities.ProfilActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.ProfilActiviy" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".activities.LokalLayoutActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.LokalLayoutAct" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
Thank you for your answer in advance.
http://i.stack.imgur.com/QGmEG.png
Need the Soundboard removed, whole thing and instead of that put search box.
It doesnt allow me to put images
I didn't know why my action bar title name was suddenly disappears.But icon was displayed at the top of the screeen.But Application name wasn't displayed at the top of the screen.
Below I am posted codes related to that.
HomeActivity.java:
package com.sit.loco.activity;
public class HomeActivity extends FragmentActivity
implements
VideoListFragment.OnVideoSelectedListener,ActionBar.OnNavigationListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// add channel list array to actionbar spinner
Context context = getActionBar().getThemedContext();
ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(context, R.array.channel_name, R.layout.sherlock_spinner_item);
list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
// remove actionbar title and add spinner to actionbar
getActionBar().setDisplayShowTitleEnabled(false);
getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
getActionBar().setListNavigationCallbacks(list, this);
// position = getIntent().getExtras().getInt("position");
Log.v("position", position + "");
appData = ((GemsApplication) this.getApplication()).getAppData();
AppPreferences.setAppPreferences(getApplicationContext());
actionabar = getActionBar();
actionabar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// actionabar.setDisplayHomeAsUpEnabled(true);
viewpager = (ViewPager) findViewById(R.id.pager);
fm = getSupportFragmentManager();
/** Defining a listener for pageChange */
ViewPager.SimpleOnPageChangeListener pageChangeListener = new ViewPager.SimpleOnPageChangeListener() {
#Override
public void onPageSelected(int position) {
super.onPageSelected(position);
actionabar.setSelectedNavigationItem(position);
}
};
}
Manifest:
<application
android:name="com.sit.loco.app.GemsApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.sit.loco.activity.SplashActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<application>
In res/menu/home.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menuShare"
android:title="#string/share_it"
android:icon="#drawable/ic_action_share"
android:showAsAction="always|withText"/>
<item
android:id="#+id/menuRate"
android:title="#string/rate_it"
android:icon="#drawable/ic_action_good"
android:showAsAction="always|withText"/>
<item
android:id="#+id/menuAbout"
android:title="#string/about"
android:icon="#drawable/ic_action_info"
android:showAsAction="always|withText"/>
</menu>
I didn't know how to solve this.Anybody can help me with this.Thank you.
You have this line:
getActionBar().setDisplayShowTitleEnabled(false);
It removes the title from the action bar. Either change it to:
getActionBar().setDisplayShowTitleEnabled(true);
or simply remove it completely.
On android device 4.0.1 I am trying to build application with ActionBar but getting the NullPointException. I have tried the following solutions:
Adding Theme Theme.Holo.Light to the application theme.
In OnCreate of Activity, setting ActionBar feature before setContentView as requestWindowFeature(Window.FEATURE_ACTION_BAR).
Used SherlockActivity and called getSupportActionBar()
But no luck. In all methods, I am getting null ActionBar. Can anyone please point me out what is the issue. I am pasting Activity and AndroidManifest.xml here.
AndroidManifest.xml
<code>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tzoomers.birthdaysdiary"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo.Light">
<activity
android:name="com.tzoomers.birthdaysdiary.BirthdaysDiary"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ContentActivity">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".SyncActivity">
</activity>
</application>
</manifest>
</code>
SyncActivity.java
<code>
public class SyncActivity extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.layout_sync_activity);
ActionBar actionBar = getActionBar();
if(actionBar != null)
{
getActionBar().setDisplayHomeAsUpEnabled(false);
}
else
{
Toast.makeText(this, "Action bar is null", Toast.LENGTH_SHORT).show();
}
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
return super.onOptionsItemSelected(item);
}
}
Please help what can be exact issue instead of pointing urls. I have tried all the solutions. If I am missing something in XML or JAVA files please point that.
Thanks in advance.
I JUST solved this problem myself, with the new updates its a bit tricky and some of the old fixes don't work as well anymore. Try this:
set your MainActivity Java code to extend ActionBarActivity
use getSupportAcionBar(); call to retrieve your action bar
Be sure your (custom) TabListener extends android.support.v7.app.ActionBar.TabListener
you can use FragmentManager to add and remove tab Fragments when tabs are selected and unselected.
Here's some of my code snippets to help illustrate, hope it works for you too :)
public class MainActivity extends ActionBarActivity
{
#Override
protected void onCreate(Bundle savedInstanceState) //Overrode Default Constructor
{
super.onCreate(savedInstanceState);
android.support.v7.app.ActionBar tabsActionBar = getSupportActionBar();
/***following changes ActionBar to a Tabbed ActionBar***/
tabsActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);`
android.support.v7.app.ActionBar.Tab tabArray = tabsActionBar.newTab();to later contain 'inflated' digitalClock (tabbed) UI
tabArray.setText(R.string.tab_one);
/***following sets clockTabListener private class as Listener for
* this object***/
tabArray.setTabListener( new clockTabListener( this, digitalClockFragment.class.getName() ) );//actual call to digitalClockFragment
tabsActionBar.addTab(tabArray);//adds TabArray to Action Bar Tab(s)
/******Second call for setting New Tab to AnalogClockFragment******/
tabArray = tabsActionBar.newTab();
tabArray.setText(R.string.tab_two);
tabArray.setTabListener( new clockTabListener( this, analogClockFragment.class.getName() ) );//actual call to analogClockFragment
tabsActionBar.addTab(tabArray);
private class clockTabListener implements android.support.v7.app.ActionBar.TabListener
{
private final Activity currentActivity;
private final String currentFragment;
private Fragment launchFragment;
private android.app.FragmentManager frgManager;
public clockTabListener(Activity activityName, String fragmentName)
{
currentActivity = activityName;
currentFragment = fragmentName;
frgManager = getFragmentManager();
}
/******************************************************************/
/******************************************************************/
/******************************************************************/
#Override
public void onTabSelected(android.support.v7.app.ActionBar.Tab arg0,
android.support.v4.app.FragmentTransaction arg1)
{
launchFragment = Fragment.instantiate(currentActivity, currentFragment);
frgManager.beginTransaction().replace(android.R.id.content, launchFragment).commit();
}
How can I get the menu icon to appear on the bottom bar?
It seems too wasteful to have a full bar, empty, just for the menu icon.
My target is Jelly Bean, I am not using Sherlock.
package com.example.test;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.Menu;
public class MainActivity extends Activity implements ActionBar.TabListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Set up the action bar.
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Tab tab = actionBar.newTab().setTabListener(this).setText("TAB LEFT");
actionBar.addTab(tab);
tab = actionBar.newTab().setTabListener(this).setText("TAB RIGHT");
actionBar.addTab(tab);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {}
#Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {}
#Override
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {}
}
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:targetSdkVersion="10" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.test.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
In your AndroidManifest you have to set the targetSdkVersion to 13 or earlier like this:
<uses-sdk android:targetSdkVersion="13" />
The overflow menu then moves to the bottom since Android tries to be version compatible
You can add this entry under the "application" tag in your manifest:
android:uiOptions="splitActionBarWhenNarrow"
read about it here.