Problem: My sliding menu only show empty view(with white background)
I use sliding menu which is widely used for facebook-like menu. (https://github.com/jfeinstein10/SlidingMenu)
But in my project, sliding menu is not showing any layout but only shows white background.
I've used sliding menu in my other projects before without any problem.
The big difference is I use actionbarsherlock in my new Project (And pager adapter).
Below is class definition of my Main activity:
public class MainActivity extends SlidingFragmentActivity {
And modify sliding menu libarary like below to support actionbar
public class SlidingFragmentActivity extends SherlockFragmentActivity implements SlidingActivityBase {
And setup sliding Menu as below in my main activity:
private void setupSlidingMenu(){
setBehindContentView(myMenu);
menu = getSlidingMenu();
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
menu.setShadowWidthRes(R.dimen.shadow_width);
menu.setShadowDrawable(R.drawable.shadow);
menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
menu.setFadeDegree(0.35f);
}
I also test both very simple layout with one textview and simple Fragment but both trial shows same result.
Both my project and sliding menu library have dependency on ActionbarSherlock library.
Thanks for help in advance.
I solve my problem by myself.
Problem is that I use below theme in my main activity.
<style name="WhiteTheme.VPI" parent="Theme.Sherlock.Light">
<item name="vpiTabPageIndicatorStyle">#style/CustomTabPageIndicator</item>
<item name="actionBarStyle">#style/WhiteTheme.ActionBarStyle</item>
<item name="android:actionBarStyle">#style/WhiteTheme.ActionBarStyle</item>
<item name="android:background">#ffffff</item>
</style>
And <item name="android:background">#ffffff</item> make whole my sliding menu white and hiding every layout. Don't actually understand why this attribute hide everything.
Related
I have a Activity in which I have created NavigationDrawer functionality and rest I have fragments using this tutorial
My problem is I want that if I navigate using navigation drawer to all fragments except home like photos, notification, etc. It must show a back button instead of hamburger icon and also includes sliding navigation. I am not able to implement this.
Also want to change toolbar back button color. Please help.
to change back button color try this.
<style name="toolbar_theme" parent="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="colorControlNormal">#color/arrow_color</item>
</style>
or
<style name="CustomTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorControlNormal">#color/arrow_color</item>
</style>
You can do actionBarDrawerToggle.setHomeAsUpIndicator(R.drawable.ic_new_icon); where toggle is your ActionBarDrawerToggle instance
To change Drawer icon to Back arrow use:
MenuFragment fragment = new MenuFragment();
//disable the toggle menu and show up carat
theDrawerToggle.setDrawerIndicatorEnabled(false); // add this
getSupportFragmentManager().beginTransaction().replace(R.id.frag_layout,fragment).addToBackStack(null).commit();
Add this code in your Drawer Item's Fragment Transaction without the Home Fragment
To revert back the change:
overwrite onBackPressed() in your Activity
#Override
public void onBackPressed() {
super.onBackPressed();
// turn on the Navigation Drawer image;
setDrawerIndicatorEnabled(true)
}
I have a toolbar, to which I have attached a sliding tab layout, using these two classes: SlidingTabLayout, SlidingTabStrip.
When I long press an item, the contextual action bar appears and overlays the toolbar, using <item name="windowActionModeOverlay">true</item> in my styles.xml. The problem is that the Tabs are still clickable, and swipable. I have tried setClickable(false), which didn't work.
How do I make the tabs not clickable, so that I can then change the "state look" of the tabs to a disabled state, with the code in a xml file within the drawable folder, as seen below.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_activated="true" android:drawable="#color/primary_dark" />
<item android:drawable="#android:color/transparent" />
Any help is much appreciated thanks.
Put a flag in your SlidingTabLayout isActionModeEnabled.
Set it every time Action mode is created and unset it on every destruction.
Based on which configure the onClick() of TabClickListener class so that if isActionModeEnabled == true then do nothing and change the background of all tabViews or whatever you want to do with it.
There are a lot of queries here about adding icons to ActionBar but none solved my problem. If you know a duplicate of this question, feel free to comment or close this question.
I migrated my project to IntelliJ and I didn't encounter this problem with my previous IDE (Eclipse).
PROBLEM: The app icon is not displayed in the ActionBar.
I think it's supposed to be added by default that's why I can't add it through its XML
Here's its 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="always" />
</menu>
Thanks!
As of AppCompat version 21, the Action Bar follows the material design guidelines and uses a Toolbar:
A title and subtitle. The title should be a signpost for the Toolbar's current position in the navigation hierarchy and the content contained there. The subtitle, if present should indicate any extended information about the current content. If an app uses a logo image it should strongly consider omitting a title and subtitle.
In modern Android UIs developers should lean more on a visually distinct color scheme for toolbars than on their application icon. The use of application icon plus title as a standard layout is discouraged on API 21 devices and newer.
However, if you want an application icon, setLogo() is the correct method.
Update your onCreate() method with the code below.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setLogo(R.drawable.ic_launcher);
getSupportActionBar().setDisplayUseLogoEnabled(true);
setContentView(R.layout.activity_main);
}
NOTE: ic_launcher is the icon you want to display in your actionbar. To display it, add the icon in the drawable folder of your app project.
In your Style.xml file:
<style name="MyTheme_ActionBar" parent="#style/Theme.AppCompat.Light">
<item name="icon">#drawable/actionbar_logo</item>
</style>
In activity add this code:
ActionBar mActionBar = getSupportActionBar();
mActionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
If you don't care about the Material theme and are fine having an Activity that looks more JellyBean/Kitkat style and includes the icon in the Action Bar, you can do the following:
First, change themes setting in styles.xml from this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
To this:
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
Now change all your Activities to inherit from android.app.Activity instead of android.support.v7.app.ActionBarActivity. That is:
Change this:
import android.support.v7.app.ActionBarActivity;
public class MainActivity extends ActionBarActivity{
To this:
import android.app.Activity;
public class MainActivity extends Activity {
The end of result of doing both of the above steps is that the icon as specified by the android:icon attribute in AndroidManifest.xml will appear in the Action Bar.
This worked for me. Your onCreate method should have these lines:
ActionBar menu = getSupportActionBar();
menu.setDisplayShowHomeEnabled(true);
menu.setIcon(R.mipmap.imageFile);
Make sure the imageFile is a .png in the mipmap folder. To get the icon exactly at the start of your action bar, the mipmap folder should have multiple versions of the image file in all screen sizes: hdpi, mdpi, xhdpi, xxhdpi, xxxhdpi, etc.
Setting Icon On the Action Bar
Showing Icon On the Action Bar Can Be Tricky
If you are extending Activity this should be enough:
getActionBar().setDisplayShowHomeEnabled(true);
If you are extending AppCompatActivity then additional code is needed:
ActionBar actionBar = getSupportActionBar();
actionBar.setIcon(R.mipmap.ic_launcher);
actionBar.setDisplayShowHomeEnabled(true);
I'm writing an Android app based on a MainActivity with several attached Fragments. The ActionBar displays navigation tabs, along with icons. Each fragment has a set of icons associated with it; MainActivity has a 'Close' icon which is also displayed. I display them by calling setHasOptionsMenu(true), and inflating the menu xml in onCreateOptionsMenu.
Menu XML example:
<item
android:id="#+id/apply"
android:orderInCategory="50"
android:title="#string/apply"
app:showAsAction="always"
android:showAsAction="always"/>
<item
android:id="#+id/reset"
android:orderInCategory="75"
android:title="#string/reset"
app:showAsAction="always"
android:showAsAction="always"/>
</menu>
Right now, sometimes the icons display correctly, and other times the action bar appears to be missing icons. The missing icons don't appear in the overflow (I have a physical menu button) either. I've tried hiding all menus except the one belonging to the active fragment in PageView.setOnPageChangeListener, but that hasn't helped.
Thanks!
Remove app:showAsAction=... attributes and delete the app namespace from the menu xml file.
I'm using the sherlok-actionbar and trying to apply a divider between the action buttons.
I have th style but the dividers are not visible, why?
<style name="Theme.SherlockCustom" parent="#style/Theme.Sherlock.Light">
<item name="abBackground">#drawable/actionbar_gradient</item>
<item name="abIcon">#drawable/logo</item>
<item name="abDivider">#drawable/ab_divider</item>
</style>
Thanks!
ActionBarSherlock v3.5 was updated to include the sources from Ice Cream Sandwich for all action-item related views and classes. This means that the rules for placing a divider between two action items follows the same rules as it would on ICS.
A divider would only be shown between the following:
Text-only followed by text-only
Icon-only followed by text-only
Text and icon followed by text-only
If you want to override this behavior (on pre-3.0 only) make the following change to ActionItemView.java:
What you can do is to add a view next to the actionbar item that will look like the separator (works on all Android versions)
<item
android:actionViewClass="com.example.ActionSeparatorView"
android:showAsAction="always"
android:title="#null"/>
and the ActionSeparatorView is a simple extension of the ImageView with the drawable you want to show as a separator
public class ActionSeparatorView extends ImageView {
public ActionSeparatorView (Context context) {
super(context);
setImageDrawable(getResources().getDrawable(R.drawable.separator));
}
}