this.navDrawerToggle = new ActionBarDrawerToggle(this,this.getApplicationContext(), this.navDrawerLayout,R.drawable.ic_drawer, R.string.app_name, R.string.app_name ){
#Override
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(navDrawerTitle);
invalidateOptionsMenu();
}
#Override
public void onDrawerClosed(View drawerView) {
getActionBar().setTitle(appTitle);
invalidateOptionsMenu();
}
};
I'm new to android i i'm making an app in which i was using Navigation Drawer i was following a tutorial but then in the end i stuck on ActionBarDrawerToggle() which i think is now deprecated and that tutorial was made earlier please can anyone tell me how to use deprecated ActionBarDrawerToggle or any other way to use android.support.v4.app.ActionBarDrawerToggle; ??
please explain in detail as i'm new to android and programming.
i also imported
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
but still not working.
As the official oracle Java documentation hints,
You may have heard the term, "self-deprecating humor," or humor that
minimizes the speaker's importance.
A deprecated class or method is like that. It is no longer important.
It is so unimportant, in fact, that you should no longer use it, since
it has been superseded and may cease to exist in the future.
And also stated in the official android documentation
This class is deprecated. Please use ActionBarDrawerToggle in
support-v7-appcompat.
That being said, you should try to find a different solution to your problem. For example, you could use the support v7 version as suggested by the Android docs. Here is an example on what you could do instead of using a deprecated class.
Do not use the support v4 ActionBarDrawerToggle. Deprecated libraries will crash your app unexpectedly. I know this by experience. Use the support v7 one. Here is a pretty simple implementation.
Related
How to Implement NavigationDrawer icon like in Android L.
I have updated play store app where i can see icon of navigation drawer something like this:
Here big change is the new “hamburger” button, which is bigger, spaced off from the left edge, and no longer has a category icon. Clicking on it opens up the side menu, and the icons turns into a back arrow with a smooth little animation.
Is it possible to implement the same in lower versions of android ?
Any example or sample ?
Edit - October 18th
As of October 17th it's not necessary to use a Third-Party library for this anymore. Google just released the Android 5.0 SDK along with a new v7 appcompat library. The new v7 appcompat added support for material design user interfaces and updated ActionBarDrawerToggle, which contains the menu-to-arrow animation.
So in order to have the Burger-to-Arrow animation in your NavigationDrawer you just have to use the new ActionBarDrawerToggle (import android.support.v7.app.ActionBarDrawerToggle) and the NavigationDrawer like before (see Developer Training).
While the ActionView by markushi gives you the desired transformation between the burger-icon and the arrow it lacks the option for being used in the "Standard" ActionBar. For this you should consider to use the library material-menu by balysv.
The usage of the library itself may be straightforward, but if you've used the ActionBarDrawerToggle previously you should remove it.
Following just a little "How to" for everyone who wants to use the DrawerLayout without the ActionBarDrawerToggle but with the MaterialMenu library:
1 - Add library in build.gradle file
dependencies {
//...
compile 'com.balysv.materialmenu:material-menu:1.3.1'
}
2 - Init MaterialMenuIcon
materialMenu = new MaterialMenuIcon(this, Color.WHITE, MaterialMenuDrawable.Stroke.THIN);
3 - Set DrawerListener and change IconState accordingly
mDrawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {
#Override
public void onDrawerSlide(View drawerView, float slideOffset) {
materialMenu.setTransformationOffset(
MaterialMenuDrawable.AnimationState.BURGER_ARROW,
isDrawerOpened ? 2 - slideOffset : slideOffset
);
}
#Override
public void onDrawerOpened(View drawerView) {
isDrawerOpened = true;
}
#Override
public void onDrawerClosed(View drawerView) {
isDrawerOpened = false;
}
});
Note: isDrawerOpened should be global variable
4 - Open/Close NavDrawer
Add this to onOptionsItemSelected(MenuItem item)
if(item.getItemId() == android.R.id.home) {
if (mDrawerLayout.isDrawerVisible(GravityCompat.START)) {
mDrawerLayout.closeDrawer(GravityCompat.START);
} else {
mDrawerLayout.openDrawer(GravityCompat.START);
}
}
Note: Since we're not using the ActionBarDrawerToggle we have do this on our own.
Further steps like saving the state of the MenuIcon can be found here.
Edit
As mentioned by Piyush Kukadiya MaterialMenu uses NineOldAndroids for compatibility reasons. If you don't want this because your app only supports API-Level 11 and above here's what you roughly need to do (though I'd say it’s probably not worth the hassle - furthermore you'll only save 39kb):
Download the Library from GitHub
Import it as a new module to your Project
Set it as a dependency to your app-module
Remove compile 'com.nineoldandroids:library:2.4.0' from build.gradle file of the library and set minSdk to 11
Remove any import referecing com.nineoldandroids.*
As Google release the new support library Android Support Library, revision 21,you can see how to achieve the effect in ActionBarDrawerToggle this page.
I am using this :
import appcom v7 library
to import appcom V7 library to make my application compatible with older versions.But when i import it then try to finish the setup then i am not able to do so. finish button becomes useless. Where i am wrong ???? any useful help will be appreciated.
Here is the snapshot.
I'm working on a phonegap project which contains a canvas overlayed with kinetic.js, which allows a user to pinch zoom and pan around an image, then draw annotations on it. it works spliendidly in a browser and on windows and apple tablets, but of course android is a good bit slower.
as a solution, i've released the app using https://github.com/thedracle/cordova-android-chromeview. after switching my main java class to use ChromeView as the webview, i'm getting this error on startup:
12-03 13:21:09.083: E/chromium(13917): [ERROR:aw_browser_context.cc(191)] Not implemented reached in virtual quota::SpecialStoragePolicy* android_webview::AwBrowserContext::GetSpecialStoragePolicy()
after debugging through the codebase, it looks like the error is triggering here:
private void setNativeContentsClientBridge(int nativeContentsClientBridge) {
mNativeContentsClientBridge = nativeContentsClientBridge;
}
(AwContentsClientBridge.java line 36).
i'm trying to find out what the nativeContentsClientBridge int is. My value is 1611312352 but i haven't a notion of what that represents.
my gut feel is that the chromium browser is missing an implementation for accessing localstorage. i found this bug:
https://github.com/pwnall/chromeview/issues/27
where someone is experiencing the same thing, but there is no solution.
for assistance, this is my main activity class:
package com.companion;
import org.apache.cordova.Config;
import org.apache.cordova.CordovaActivity;
import us.costan.chrome.ChromeSettings;
import us.costan.chrome.ChromeView;
import android.os.Bundle;
public class CompanionApp extends CordovaActivity
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
ChromeView chromeView = new ChromeView(CompanionApp.this);
ChromeSettings settings = chromeView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDatabaseEnabled(true);
settings.setDomStorageEnabled(true);
setContentView(chromeView);
super.loadUrl(Config.getStartUrl());
}
}
Thanks for your help,
Margaret
Don't know if it's normal, but it seems that a method's not implemented in Chromium base code : https://github.com/01org/pa-chromium/blob/master/android_webview/browser/aw_browser_context.cc
Here's that particular method:
quota::SpecialStoragePolicy* AwBrowserContext::GetSpecialStoragePolicy() {
// TODO(boliu): Implement this so we are not relying on default behavior.
NOTIMPLEMENTED();
return NULL;
}
I hope it helps :)
I have been attempting to create a simple TabActivity with 3 Tabs. All works except if I put android:minSdkVersion="11" in the Manifest file, the icons are not shown. If I set `minSdkVersion="10", all is well.
I have looked high and low, but I have not been able to determine what is wrong.
I have put the same images in the seemingly appropriate resource directories:
res/drawable-hdpi-v5
res/drawable-ldpi-v5
res/drawable-mdpi-v5
res/drawable-xhdpi-v5
And the the code is simple:
import android.app.TabActivity;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabWidget;
public class Review extends TabActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TabHost tabs = getTabHost();
getLayoutInflater().inflate(R.layout.main,
tabs.getTabContentView(), true);
Resources resources=getResources();
Log.d("testing", String.format("icon: %d.%d",
resources.getDrawable(R.drawable.review).getIntrinsicWidth(),
resources.getDrawable(R.drawable.review).getIntrinsicHeight()));
TabHost.TabSpec details = tabs.newTabSpec("review"). setContent(R.id.review).
setIndicator(getString(R.string.review),
resources.getDrawable(R.drawable.review));
TabHost.TabSpec gallery=tabs.newTabSpec("gallery").setContent(R.id.photos)
.setIndicator(getString(R.string.gallery),
resources.getDrawable(R.drawable.photos));
TabHost.TabSpec reservation=tabs.newTabSpec("reservation").
setContent(R.id.reservation)
.setIndicator(getString(R.string.reservation),
resources.getDrawable(R.drawable.reservation));
tabs.addTab(details);
tabs.addTab(gallery);
tabs.addTab(reservation);
}
}
In digging into this, the only difference I can see internally under android 2.0 vs 3.0 is that Android uses a RelativeLayout instead of a LinearLayout in the 2.0 implementation.
Just to be certain that the icons images are being found, Log.d of above shows:
icon: 32.32 as it should.
Why does this shift from android 2.0 to 3.0 do this???? I am hopeful that someone else has run into this and it is obvious. Thanks very much for your help!
-- UPDATE:
I discovered today, as I looked more closely at what is actually happening when this code is built for android 3.0+, I learned that the ImageView's that come about when SetIndeicator(string, drawable) is called for each TabSpec, are actually never set and are actually NULL (ImageView.mDrawable==null) and INVISBLE.
If I force set those drawables to be set, and call ImageView.setVisiblity(View.VISIBLE) then they show up. However under android 2.0 they appear stacked with the image above and the text below as in:
<image>
<text>
Under android 3.0 they appear (when forced as above) side by side as in:
<image><text>
Thus it seems that things have changed a great deal and I need to investigate the changes for android 3.0 more carefully.
Stay tuned for more...
-- Final UPDATE:
Ultimately, I abandoned this avenue and decided that this style of doing things changed and is perhaps now depreciated and there are other better ways to do this and the icons are a bit old style.
strange, this solves the problem
//bmOptions.inSampleSize = 1;
//or better
bmOptions.inScaled = false;
more at:
https://stackoverflow.com/a/12088287/1320686
With this code:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
. . .
Button buttonAuthorizeUsers = (Button) findViewById(R.id.buttonAuthorizeUsers);
buttonAuthorizeUsers.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent configure = new Intent(OnDemandAndAutomatic_Activity.this, Configure_Activity.class);
OnDemandAndAutomatic_Activity.this.startActivity(configure);
}
});
I'm getting:
The method onClick(View) of type new View.OnClickListener(){} must override a superclass method
It would seem that this problem is sometimes caused by a Project | Properties | Java Compiler being set to 1.5.
Although I'm virtually I'd had this problem before, and changed it to 1.6, somehow it WAS 1.5 again.
HOWEVER, that (changing it to 1.6) did not solve the problem. I'm still getting that same err msg, after cleaning, building, and F11ing...???
I would recommend that you uncheck "Enable project specific settings", click "Configure Workspace Settings..." and change "Compiler Compliance Level" to 1.6 or above. Otherwise you would have to specify it every time.
If you need a specific compliance level for a specific project, you need to verify every other project that need compliance level 1.6 or above is set to this.
After everything is correctly setup - clean projects and restart Eclipse. Eclipse can be such a bitch some times - this often solves problems for me.
Two things to consider:
1) Take a look at your imports - are you sure that View.OnClickListener is imported, but not lets say DialogInterface.OnClickListener
2) OnClickListener is actually an interface, that you are instantiating anonymously. So after all when writing the onClick method you are actually not overriding a super class method, but instead implementing an interface method. Annotating interface methods with #Override is a good practice, but this has been introduced in JDK 6, which means that by the time Android 1.5 or 1.6 was developed this may not has been yet introduced to the java language and hence making it an invalid syntax.
Right below the "Compiler Compliance Level", there are a few options grayed out if the "Use default compliance settings" checkbox is checked: Namely, "Generated .class files compatibility" and "Source compatibility". Verify that both of those are set to 1.6 - If not, either change the default compliance settings, or uncheck that box and tweak them directly.
Button buttonAuthorizeUsers = (Button) findViewById(R.id.buttonAuthorizeUsers);
buttonAuthorizeUsers.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent configure = new Intent(OnDemandAndAutomatic_Activity.this,Configure_Activity.class);
OnDemandAndAutomatic_Activity.this.startActivity(configure);
}
});
try to replace this line
buttonAuthorizeUsers.setOnClickListener(new View.OnClickListener() {});
this error you got happened when your trying to assignee the On-click to unexpected type !
So, beleive me Eclipse IDE most of time will import DialogInterface instead of View so write it by your self.
daigoor is right. Eclipse always try to do this 'import android.content.DialogInterface.OnClickListener' instead of the doing this -> 'import android.view.View.OnClickListener'. That solves my problem.