I'm adding contextual action bar after long click of RecyclerView element. Problem is toolbar is still visible. Contextual action bar doesn't overlap completely.
Tried searching for info, but no or very little info found.
My toolbar:
After adding contextual action bar:
As you can see toolbar is still visible at the bottom.
Theme im using:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="windowActionModeOverlay">true</item>
</style>
My toolbar:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toolbar"
android:minHeight="?android:attr/actionBarSize"
android:background="#F7F8F9"
app:titleTextColor="#color/colorPrimaryDark" />
cab.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_upload"
android:title="Upload"
android:icon="#drawable/ic_file_upload_black_24dp"
app:showAsAction="always" />
<item
android:id="#+id/action_reboot"
android:title="Reboot"
android:icon="#drawable/ic_refresh_black_24dp"
app:showAsAction="always"/>
</menu>
This is how i'm starting Contextual action bar:
startSupportActionMode(new android.support.v7.view.ActionMode.Callback() {
#Override
public boolean onCreateActionMode(android.support.v7.view.ActionMode mode, Menu menu) {
mode.getMenuInflater().inflate(R.menu.cab, menu);
return true;
}
#Override
public boolean onPrepareActionMode(android.support.v7.view.ActionMode mode, Menu menu) {
return false;
}
#Override
public boolean onActionItemClicked(android.support.v7.view.ActionMode mode, MenuItem item) {
return false;
}
#Override
public void onDestroyActionMode(android.support.v7.view.ActionMode mode) {
}
});
My readings:
contextual action bar padding in Android
Contextual action bar does not overlay my toolbar
Tried pretty much everything from questions above. None of them have helped.
P.S. Tried increasing/decreasing size of the toolbar, but visible line is still visible
So how to make Contextual action bar overlap toolbar completely?
Add
<item name="actionModeBackground">your_color</item>
in your styles.xml file, it will overlay your toolbar completely.
Related
My problem is with menu item icon . I can't see any icon in action bar . There is simply just one activity in my app . In fact it's a simple hello word and i want add an icon to action bar
menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<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"
>
<!-- black icon -->
<item
android:id="#+id/action_create_order"
android:title="create order"
android:orderInCategory="1"
app:showAsAction="ifRoom"
android:icon="#drawable/ic_add_black_36dp"
>
</item>
<!-- white icon -->
<item
android:id="#+id/action_setting"
android:title="settins"
app:showAsAction="never"
android:orderInCategory="100"
>
</item>
</menu>
MainActivity.java:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main , menu);
return super.onCreateOptionsMenu(menu);
}
}
why icon doesn't appear in action bar ?
try by changing
app:showAsAction="ifRoom"
to
app:showAsAction="always"
EDIT:
I suggest you change your Activity to AppCompatActivity and also use a Toolbar as your ActionBar
If you use extends Activity you have to use android:showAsAction inside menu.xml
If you want to use app:showAsAction, you have to extend AppCompatActivity as Adolfo Lozano Mendez suggested
Maybe there is no enough place to show icon. Try to rotate the screen (phone/emulator).
I tried to add buttons with icons to the Action Bar so I followed the info on the android developer page. However despite having assigned icons, the buttons will only be displayed in the overflow and not on the bar itself. I want the buttons to appear on the bar with their icons. My code:
The onOptionsItemSelected method of the activity
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_new:
launchAddRuleActivity();
return true;
case R.id.action_settings:
return true;
default:
return super.onOptionsItemSelected(item);
}
}
The onCreateOptionsMenu of the 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.main, menu);
return true;
}
The main.xml for the action bar layout:
<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.mhmt.autotextmate.Main" >
<!-- New, should appear as action button -->
<item
android:id="#+id/action_new"
android:icon="#drawable/ic_action_new"
android:showAsAction="ifRoom"
android:title="#string/action_new"/>
<!-- Settings, should always be in the overflow -->
<item
android:id="#+id/action_settings"
android:icon="#drawable/ic_action_save"
android:showAsAction="never"
android:title="#string/action_settings"/>
Lastly, the target and min SDKs:
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="22" />
I got the drawables from here so the size shouldnt be a problem. This class does extend ActionBarActivity, and imports android.support.v7.app.ActionBarActivity. I'm currently testing on a Google Nexus emulator running Android 5.1.1 with 720x1280 resolution.
I must be doing something wrong, can anyone see what I'm missing to display the buttons with their icons, and not in the overflow?
Try this app:showAsAction="always"
<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.mhmt.autotextmate.Main" >
<!-- New, should appear as action button -->
<item
android:id="#+id/action_new"
android:icon="#drawable/ic_action_new"
app:showAsAction="always"
android:title="#string/action_new"/>
<!-- Settings, should always be in the overflow -->
<item
android:id="#+id/action_settings"
android:icon="#drawable/ic_action_save"
app:showAsAction="always"
android:title="#string/action_settings"/>
I am using the ActionMode via:
#Override
public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.menu_list_context, menu);
this.mActionMode = mode;
return true;
}
And my resource file menu_list_context is:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
<item android:id="#+id/discard_button"
android:icon="#drawable/ic_action_discard"
android:title="delete"
android:showAsAction="ifRoom" />
The style for my ActionBar is:
<style name="MyActionBar"
parent="#android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:background">#color/background_holo_light</item>
</style>
where <color name="background_holo_light">#dddddd</color>.
With these settings, my ActionBar under ActionMode looks like this:
The icon has the background of my ActionBar (holo light), but the ActionMode background seems white. How can I fix the icon background to have the ActionMode background (including the blue bottom line)?
You could try using the Action Bar Style Generator. This is the only way I know of to get exact ActionBar styles that actually works.
I am currently having an issue showing the option menu items on the actionbar. For some reason, the items only show on the overflow menu and this is true for post ICS devices as well. I am using the v7-appcompat library to support sdks from version 8 onwards.
In the main activity I have:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.wild_news, menu);
return true;
}
My menu items are defined as follow:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
**xmlns:app="http://schemas.android.com/apk/res-auto"** >
<item
android:id="#+id/menu_refresh"
android:icon="#drawable/ic_action_refresh"
**app:showAsAction="always"**
android:title="#string/menuTitle_refresh"/>
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
**app:showAsAction="ifRoom"**
android:title="#string/action_settings"/>
I also have a spinner in the actionbar with the following xml layout:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:minWidth="140dp"
android:layout_gravity="center_vertical"
style="#style/ActionBarNavListTitle" />
I can't seem to get my head around it.
Great I found the issue to be related to a mismatch in the ActionBar style definition which I have resolved now:
<style name="ActionBarStyle" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
My action bar shows the app icon on the left, then has a large space, and then shows some of my menu items on the right (the rest go into overflow). The problem is that the "large space" is big enough to hold several more icons. Why isn't it being used?
My menu resource looks like this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/menu_a"
android:icon="#drawable/a"
android:title="a"
android:orderInCategory="100"
android:showAsAction="ifRoom" >
<menu>
<item ... />
...
</menu>
</item>
...
<item
android:id="#+id/menu_n"
android:icon="#drawable/n"
android:title="n"
android:orderInCategory="100"
android:showAsAction="ifRoom" >
...
</item>
</menu>
In my Activity, I have:
#Override
public void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView (R.layout.main_activity);
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setHomeButtonEnabled (true);
...
}
and
#Override
public boolean onCreateOptionsMenu (Menu menu)
{
getMenuInflater().inflate(R.menu.nav_menu, menu);
return true;
}
I have a suspicion it has something to do with the app title (setDispalyShowTitleEnabled), which I have disabled. Maybe I'm doing it wrong?
Nothing wrong with your code.
AtionBar by default allows only 2-3 menu items even when there is enough room to accommodate 4-5.
May be to maintain better UI.
So, instead of
android:showAsAction="ifRoom"
use
android:showAsAction="always"
to have the MenuItems always present on the ActionBar instead of going into the overflow menu.