split action bar doesn't appear? - android

i want to make action bar top and down in android 4.03 make code but when i run it it doesn't appear , i don't know what is wrong , i search for reson before asking here but i didn't find anything
here is menu/style.xml code:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/first"
android:icon="#drawable/cat"
/>
<item
android:id="#+id/first"
android:icon="#drawable/phone"
/>
<item
android:id="#+id/first"
android:icon="#drawable/music"
/>
<item
android:id="#+id/first"
android:icon="#drawable/dialog"
/>
<item
android:id="#+id/first"
android:icon="#drawable/file"
/>
<item
android:id="#+id/first"
android:icon="#drawable/contact"
/>
<item
android:id="#+id/first"
android:icon="#drawable/contact"
/>
</menu>
manifest code:
<activity
android:label="#string/app_name"
android:name=".CalendarActivity"
android:uiOptions="splitActionBarWhenNarrow"
>
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and activity code:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater i=getMenuInflater();
i.inflate(R.menu.style, menu);
return true;
}
because this is first use to android 4.0 i'm a little confused, why my items in black color i can't see them ??

Have you set android:minSdkVersion="14" in your manifest? Because android:uiOptions is compatible with older versions of Android so you don't see any error!
Remember also that
Android adjusts the action bar's appearance in a variety of ways,
based on the current screen size
See Using split action bar for more info.

I think you need to add
android:showAsAction="always"
to every item in the menu xml.

Related

How to add a split ActionBar in android.I have got everything right but it still doesn't work.

here is my code
MainActivity
public class MainActivity extends ActionBarActivity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
}
menu_main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
<item android:id="#+id/action_settings" android:title="#string/action_settings"
android:orderInCategory="100" app:showAsAction="never" />
<item android:id="#+id/one" android:title="oneone"
android:orderInCategory="100" app:showAsAction="always" />
<item android:id="#+id/two" android:title="twotwo"
android:orderInCategory="100" app:showAsAction="ifRoom" />
<item android:id="#+id/three" android:title="threethree"
android:orderInCategory="100" app:showAsAction="ifRoom" />
<item android:id="#+id/four" android:title="fourfour"
android:orderInCategory="100" app:showAsAction="ifRoom" />
</menu>
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sanjith.actionbartwo" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name=".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>
This code gives me three buttons on the actionbar and one on the overflow.
I want to get all the buttons on the bottom actionbar.I have searched the internet for this but i haven't found a solution.
Please help.
Try this http://developer.android.com/guide/topics/ui/actionbar.html#SplitBar
<manifest ...>
<activity uiOptions="splitActionBarWhenNarrow" ... >
<meta-data android:name="android.support.UI_OPTIONS"
android:value="splitActionBarWhenNarrow" />
</activity>
</manifest>
I have encountered this problem before unfortunately the action bar doesn't split by code you need to fill all the room available so the action bar would split by itself with your permission of course but there are no possible way to split it if it still have space

Android - ActionBar icon not showhing

I have trouble seeing the icons in the ActionBar.
I also read around here in StackOverFlow, but nothing...
Here is my action.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item
android:id="#+id/addAct"
android:icon="#android:drawable/ic_input_add"
android:background="#null"
app:showAsAction="always"
android:title="#string/add"
/>
<item
android:id="#+id/searchAct"
android:icon="#android:drawable/ic_menu_search"
app:showAsAction="ifRoom"
android:title="Cerca"
android:actionViewClass="android.widget.SearchView"
/>
<item
android:id="#+id/visualizza"
android:title="#string/txtVisualizza"
app:showAsAction="always"
>
</item>
Here, is AndroiManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="11"
android:maxSdkVersion="21"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".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>
<activity
android:name=".WriteActivity"
android:label="#string/title_activity_write" >
</activity>
</application>
Here, MainActivity:
public class MainActivity extends Activity { ...
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.action, menu);
return super.onCreateOptionsMenu(menu);
}
In the xml code, I have used the app for ShowAsAction, but this not seems be the problem.
Thanks for any help :)
You are developing app for material design ( Target SDK = 21).
It does not support Activity.
So change extends Activity to extends ActionBarActivity.
Now your menu will be visible.
And you can edit action bar using getSupportActionBar().

Android Search icon not showing up on Action Bar

I was following this tutorial on Android when i came across a problem. As mentioned in topic my search icon isn't showing up on the action bar.
I had problem with that step.
http://developer.android.com/training/basics/actionbar/adding-buttons.html
I think i have done everything the same but still nothing shows up.
I've seen other people having similar problem but their answers didn't work for me.
The worst thing is unlike others people problems related to search icon not showing up, mine isn't even showing up on overflow while theirs is. Maybe it can guide someone to what's my issue.
main_activity_actions.xml code below
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<!-- Search, should appear as action button -->
<item
android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
app:showAsAction="ifRoom"/>
<!-- Settings, should always be in the overflow -->
<item
android:id="#+id/action_settings"
android:title="#string/action_settings"
app:showAsAction="never"/>
</menu>
main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<!-- Search, should appear as action button -->
<item
android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
app:showAsAction="ifRoom"/>
<!-- Settings, should always be in the overflow -->
<item
android:id="#+id/action_settings"
android:title="#string/action_settings"
app:showAsAction="never"/>
</menu>
activity.main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText
android:id="#+id/edit_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="#string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/button_send"
android:onClick="sendMessage" />
</LinearLayout>
MainActivity.java
public class MainActivity extends ActionBarActivity {
public final static String EXTRA_MESSAGE = "com.pawel.androidapp.MESSAGE";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#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_activity_actions, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here.
switch(item.getItemId())
{
case R.id.action_search:
openSearch();
return true;
case R.id.action_settings:
openSettings();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void openSearch() {
Toast.makeText(this, "Search pressed", Toast.LENGTH_SHORT).show();
}
private void openSettings() {
startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));
}
public void sendMessage(View view) {
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}
androidapp manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pawel.androidapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat" >
<activity
android:name=".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>
<activity
android:name=".DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.pawel.myfirstapp.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.pawel.androidapp.MainActivity" />
</activity>
</application>
</manifest>
I had the same problem. You're using minSdkVersion="11" which is when the ActionBar APIs were defined. (http://developer.android.com/guide/topics/ui/actionbar.html)
The line I had wrong was:
app:showAsAction="ifRoom"
I had looked at the development tutorials which are illustrating use of the Support Library and my line looked the same as yours. I changed it to this:
android:showAsAction="ifRoom"
and it worked. Use the "android" namespace instead of the "app" namespace.
(https://developer.android.com/training/basics/actionbar/adding-buttons.html)
I have same problem, I got the answer after exchanging below 3 "android" to "app":
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!-- Search, should appear as action button -->
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
app:showAsAction="ifRoom"
android:orderInCategory="100" />
<!-- Settings, should always be in the overflow -->
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
app:showAsAction="always"
android:orderInCategory="101" />
</menu>
I had the ditto problem and i did not change anything in the code as others suggest above. I had downloaded the Action Pack icons from Android URL "http://developer.android.com/design/downloads/index.html#action-bar-icon-pack" and this has two folders named "Core Icons" and "Action Bar Icons". I used the icon ic_action_search from within the "Core Icons" folder and that caused the problem. I replaced the icon at "drawable" folder with the one from "Action Bar Icons/Holo Dark" and it was working the way intended. That was a moment of relief for a android developer. :)
It's more than likely down to
app:showAsAction="ifRoom"
You're basically saying only show the icon if there is room available to show it. So try :
app:showAsAction="always"
See http://developer.android.com/guide/topics/resources/menu-resource.html for more.
Edit :
Sorry, I've just noticed that you're using the namespace http://schemas.android.com/apk/res-auto for this attribute.
Does it work if you change it to :
android:showAsAction="always"
you have missed:
app:actionViewClass="android.support.v7.widget.SearchView"
from your item.
I tested your code in my project and I found that the issue was in the Manifest file.
android:theme="#style/Theme.AppCompat" >
Change it to:
android:theme="#style/Theme.AppCompat.Light" >

"Action Bar" doesn't show up

I am trying to implement action bar(appcompatv_7) on API version 8. Although there is no error in my code but the action bar won't show up, instead it will appear in text format by pressing menu button.
Here is the java code:
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
}
Code for menu:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.usingsherlockkk.MainActivity" >
<item
android:id="#+id/item1"
android:icon="#android:drawable/ic_menu_add"
android:showAsAction="ifRoom"
android:title="Title1">
</item>
<item
android:id="#+id/item2"
android:icon="#android:drawable/ic_menu_delete"
android:showAsAction="ifRoom"
android:title="Title2">
</item>
<item
android:id="#+id/reset"
android:icon="#android:drawable/ic_menu_revert"
android:showAsAction="ifRoom"
android:title="Revert">
</item>
<item
android:id="#+id/item4"
android:icon="#android:drawable/ic_menu_edit"
android:showAsAction="ifRoom"
android:title="Title4">
</item>
<item
android:id="#+id/item5"
android:icon="#android:drawable/ic_menu_help"
android:showAsAction="ifRoom"
android:title="Title5">
</item>
</menu>
Manifest file code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.usingsherlockkk"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light"
android:uiOptions="splitActionBarWhenNarrow" >
<activity
android:name="com.example.usingsherlockkk.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>
Guys my problem is that all the menu items are displayed in overflow where only the title appears. I checked it with big/small screen devices but it remains the same.
I hope I have explained my problem well enough. Let me know if something is hazy
Try this code
#Override
protected void onCreate(Bundle arg0) {
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
super.onCreate(arg0);
setContentView(R.layout.activity_main);
}
Ok guys I got the solution to my very own problem.
The problem was in defining the action items in the "menu.xml".
Android documentation says you cannot use "android:showAsAction" on older devices as it does not exist in older versions. You have to use a custom namespace. Instead of saying "android:showAsAction", use "app:showAsAction" and you are good to go. Here is the attachment from official page:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
yourapp:showAsAction="ifRoom" />
...
</menu>
Using XML attributes from the support library:
Notice that the showAsAction attribute above uses a custom namespace defined in the tag. This is necessary when using any XML attributes defined by the support library, because these attributes do not exist in the Android framework on older devices. So you must use your own namespace as a prefix for all attributes defined by the support library.
I hope it helps someone out there.
The way I did it is as follows:
There was a line in AndroidManifest.xml file
android:theme="#style/AppTheme.NoActionBar"
I simply changed it to
android:theme="#style/AppTheme"
and problem was solved.

Android: menu in action bar

i have problem putting the menu there, in the upper right corner:
android manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="it.mio.app"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="11"
android:targetSdkVersion="15" />
<application android:allowBackup="false"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Light">
<activity android:name=".Lista_preventivi"
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>
Java:
public class Lista_preventivi extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.lista_preventivi);
}
#Override
public boolean onCreateOptionsMenu(Menu menu){
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
}
menu xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/action_settings"
android:showAsAction="ifRoom"
android:title="#string/action_settings" />
</menu>
all works, but the menu appear only if i click the physical button on my phone, and it appear at the bottom like a normal menu.
ho can i have the icon menu in the upper right action bar, and show the menu there?
Thanks!
The theme which your are applying to the application is android:theme="#android:style/Theme.Light". it doesn't have an actionbar.
Change it to something which has an action bar like,
Theme.Sherlock.Light (Need to add ABS library)
Theme.Holo.Light
The code is just fine.
Add:
android:showAsAction="always" in your manifest file
If your sdk version is >3.0 .Else you have no other option other than implementing Sherlock Home Api.

Categories

Resources