I'm trying to replace the ActionBar of my app with a Toolbar but I can't because I can't use setSupportActionBar(). It says "setSupportActionBar() is undefined for the type MainActivity" even if MainActivity extends ActionBarActivity.
I don't know what to do, any help? Do you need me to post my code?
EDIT:
Now the code works but my app crashes on start and it says: "Attempt to invoke virtual method getTitle()". What do I miss?
EDIT2:
Everything works I forgot I had a Fragment and because of that it gave me nullPointer
Now use :
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
setSupportActionBar(toolbar);
XML :
android.support.v7.widget.Toolbar
Extends :
public class MainActivity extends AppCompatActivity
Without code, my only recommendation, is making sure your import statement is as follows:
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
Also make sure in your XML files that you are using
<android.support.v7.widget.Toolbar
As your toolbar tag
import androidx.appcompat.app.AppCompatActivity;
import this class instead of:
import android.support.v7.widget.Toolbar;
or
import android.widget.Toolbar;
The newer version requires the android class
Related
I'm making an Android app using appcompat using com.android.support:appcompat-v7:23.0.3 and getting following error.
Error:(22, 9) error: method setSupportActionBar in class
AppCompatActivity cannot be applied to given types; required:
android.support.v7.widget.Toolbar found: android.widget.Toolbar
reason: actual argument android.widget.Toolbar cannot be converted to
android.support.v7.widget.Toolbar by method invocation conversion
First of all appcompat 23.0.3 doesn't exist.
Use 23.0.1
com.android.support:appcompat-v7:23.0.1
Then the method setSupportActionBar works with android.support.v7.widget.Toolbar.
Check the import in your code.
When you are using the Toolbar,you have to use the right import:
import android.support.v7.widget.Toolbar;
Finally also in your layout, you have to use the right widget.
<android.support.v7.widget.Toolbar
..... />
I have problem same with you
I change extends Activity to extends ActionBarActivity
Like this:
public class myclass extends Activity
to
public class myclass extends ActionBarActivity
Change android.widget.Toolbar import statement to android.support.v7.widget.Toolbar
import android.support.v7.widget.Toolbar;
Forget ToolBar
New solution to change Name of Activities is here
Use Manifests &
android:label="name_to_be_changed"
for ex.
`<enter code hereactivity android:name=".MyActivity"
android:label="My Activity"
android:screenOrientation="portrait"/>`
I also faced the same problem while adding toolbar widget. In my case, I have changed import link to :
android.support.v7.widget.Toolbar;
and it worked fine.
just
import android.support.v7.widget.Toolbar,
import android.support.v7.app.AppCompatActivity,
and make sure that your xml file tool bar contain same like this
after that extend the class AppCompatActivity
i think this solve your problem
The problem it solved, in this discussion, I gave the solution of the problem: Solution to the problem
I created a project with Android Studio 1.1.
With support by the API 19 to 22
But now I'm having problems with compatibility libraries:
import android.support.v4.app.Fragment;
import android.app.Fragment;
I created a Navigation Drawer Activity as a base.
I created following a fragment blank.
I simply had to call this new fragment in my Navigation Drawer, or rather in my ActivityMain in onNavigationDrawerItemSelected method, but I have a problem with the libraries.
In my ActivityMain, libraries are: android.support.v4.app.Fragment;
while in the new Fragment Blank I created, the libraries are: import android.app.Fragment;
And of course when I try to interact with objects of type Fragment to maneuver the switch case, I have compatibility problems? between:
import android.app.Fragment;
import android.support.v4.app.Fragment;
What causes all this confusion?
I state that I have done nothing, if not simply create classes.
Where am I wrong?
I'm having a problem with calling me fragments when using FragmentPageAdapter in a swipe-function
The problem in images:
http://www.afbeeldinguploaden.nl/photo/view/90082/sxP3Rre
http://www.afbeeldinguploaden.nl/photo/view/90083/EefjiS4q
Anyone can help me with this or what can I do?
Your HomeFragment needs to extend android.support.v4.app.Fragment, so that means you need to import:
import android.support.v4.app.Fragment;
How can you show two fragments side by side?
I have tried FragmentTransaction.replace(R.id.fragmentcontainer, myFragment),
where myFragment inflates a layout which contains two fragments that reference to my other fragment classes.
But this gives me an error saying "myFragment cannot be cast to android.support.v4.app.Fragment.
Any help would be appreciated
check your import statements
Replace these statements
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
with these statements
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction
I trying to extends my main class from TabActivity ... I wrote the code as bellow :
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class AndroidTabAndListView extends TabActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
.
.
.
.
.
}
but I have a worning that the type TabActivity is deprecated !!!!!
Have any one any Idea about this ???
thank you in advance , Fadel
Please see the official document.
This class was deprecated in API level 13. New applications should use
Fragments instead of this class; to continue to run on older devices,
you can use the v4 support library which provides a version of the
Fragment API that is compatible down to DONUT.
See also:
"The type TabActivity is deprecated" For app tab
https://stackoverflow.com/questions/12600207/the-type-tabactivity-is-deprecated-help-to-use-in-older-device
Android: TabActivity deprecated, use Fragments?
Or if you have a more specific question, you can add more info.