Activity doesn't show actionbar - android

I joined Android Studio and Android App project a few week ago, and I'm trying to create a simple app with ActionBar options.
When I start Android Studio, following Android Dev. Training, I meet always this rendering error:
Android Studio doesn't found android.support.v7.app.ActionBarActivity (ecc...)
I resolved this error by setting a different theme. But whenever I try a new project i will do this again and again. First question: there is a way to fix this rendering problem? I meet this problem also in the MainActivity.java, where the extends ActionBarActivity is deleted with a line, telling me it is deprecated and advising me to use AppCompatActivity. Should i follow this tip?
Question number two: i read like 100 post on guys who can't show the actionbar in the activity, and I tried everything, but when I link actionbar menu with activity through:
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
I still can't view the menu I created on the actionbar.
Some images can maybe help me to explain better my problem:
http://i.stack.imgur.com/5nPFx.png
And there is the layout of my activity:
http://i58.tinypic.com/oau8ed.png
As you see, there is no icon button i added and no setting button like menu layout show.

ActionBarActivity is now deprecated use AppCompatActivity
to avoid this error:
Android Studio doesn't found android.support.v7.app.ActionBarActivity
you have to Download the latest version of the Support Library! and then you can use
import android.support.v7.app.AppCompatActivity
public class MainActivity extends AppCompatActivity{
...
...
...

Related

How to hide Android status bar in native game written with gomobile

How to hide Android status bar in native game written with gomobile?
I am experimenting with a simple native Android game written in pure Go using the gomobile tool. It should be able to use the full screen for rendering frames. However I could not find an API to hide the status bar from the native app.
Has anyone tackled this issue? If so, please share the directions.
Create a Empty Activity .
Go and find
android:theme="" on Activity XML Files
Set it to #style/Theme.AppCompat.NoActionBar
Pro Tip :
dont know other people but I always delete
Menu/Menu_Activity.Xml
That Contains Menu XML files !
Also Remove Menu.OnClick Codes Located on The Class of Your
Activity
Update :
Emm ... did you change :
public class Setup extends ActionBarActivity {
to
public class Setup extends Activity {
???
On the manifest add: theme: Theme.AppCompat.NoActionBar
For each activity page in which you dont want to show the status bar
This is how to disable the Android status bar in a native application written with gomobile:
Add this exact theme to AndroidManifest.xml:
<activity android:name="org.golang.app.GoNativeActivity"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
</activity>

Can we change Normal Activities in android to Action Bar activities

I developed an app, but now I want to change all the Activities.
They all should have an ActionBar.
Can I directly convert my code by extending the existing Activities to get an ActionBar?
I would really appreciate any help.
-Agree with above answer. doing as per follow ..
public class YourActivity extends ActionBarActivity{
}
-And..You have to add this code into your manifest file
android:theme="#style/Theme.AppCompat"
-Under application tag
Definitely you can, like this, just you will need is Android Support Library (AppCompat lib)
public class YourActivity extends ActionBarActivity
And also do necessary changes regarding with ActionBar, you can get ActionBar object like ,
ActionBar mAction = getSupportActionBar();
mAction.setTitle("Your Title");

neokrees Navigation Drawer doesn't show up

As a newbie in Android programming I'm playing with some Material Design. So I wanted to implement a Navigation Drawer. After looking for libraries I decided to use #neokrees MaterialNavigationDrawer (https://github.com/neokree/MaterialNavigationDrawer). I added it into my build.gradle and followed the instructions from the wiki.
As a base I'm using a MainActivity which holds a toolbar and a fragment.
I created a custom style for the drawer and wrote a simple NavigationDrawer subclass.
import it.neokree.materialnavigationdrawer.MaterialNavigationDrawer;
public class NavigationDrawer extends MaterialNavigationDrawer {
#Override
public void init(Bundle savedInstanceState) {
this.addSection(newSection("Section", new MainActivity.PlaceholderFragment()));
}
}
Then I added this to AndroidManifest.xml
<activity android:name=".NavigationDrawer"android:theme="#style/MyNavigationDrawerTheme" />
So everything compiles fine, the app starts up but nothing happens. So as first try I added a section to the drawer, relating to an activity. As I saw that the first item should be a fragment, I replaced it accordingly. Then I looked into the example app, but I don't get it to compile. Anyway, there is also no drawer-relevant code in the MainActivity.
So it's most probably a really dumb failure, but I have no idea anymore. So I would be thankful for any help.

ActionBarSherlock: OnOptionsItemSelected doesn't recognize R.id.home

I'm using the ActionBarSherlock library and I'm following the exact steps as suggested here and here to enable navigation to the previous screen.
My code looks like this:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
and
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// This callback is used only when mSoloFragment == true (see
// onActivityCreated above)
switch (item.getItemId()) {
case android.R.id.home:
// App icon in Action Bar clicked; go up
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Reuse the
// existing
// instance
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
But R.id.home is not recognized and home shows up in red. :-/ If I use the native actionbar the home declaration takes me to ids.xml file. But here the declaration is not found while I use the ActionBarSherlock Activity. Am I missing something?
just replace this
android.R.id.home
to
R.id.home
and check your code... run it
because
R.layout.* are layouts you provide (in res/layout, for example).
android.R.layout.* are layouts that ship with the Android SDK.
I know this is an old question but I believe the right answer is missing.
It should be be android.R.id.home because it is a platform resource, so your code is fine.
Make sure your minSdkVersion is 11 or higher since home was introduced in 11.
I remeber running into this problem and apparently its quite frequent a quick google or search through stack overflow should've given you some insight anyways check this thread out R cannot be resolved - Android error
Im pretty sure your running into same problem

Navigation Icon no longer firing SlidingMenu after implementing ActionBarSherlock

When first experimenting with the SlidingMenu library by jfeinstein10, in the example project, clicking the icon button in the action bar would cause the sliding menu to open and then close when clicked again. After implementing ActionBarSherlock and getting it to run (not throwing any errors), the icon no longer causes the menu to appear. So far I have changed the SlidingMenu library to extend SherlockActivity instead of extending android Activity as suggested in the SlidingMenu read me. I have also changed the following lines in BaseActivity:
Original:
// customize the ActionBar
if (Build.VERSION.SDK_INT >= 11) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
Changed to:
// customize the ActionBar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
It seems as if the button press is being registered in LogCat, but it's not doing anything.
I've been trying to figure this out for a while now and just wanted to see if anyone has experienced this issue or is familiar enough with both/either libraries to quickly help pinpoint where I'm going wrong or what I forgot to do.
Thanks!
this is your problem
import android.view.MenuItem
you must use Shearlock Menu not android Menu.
remove android MenuItem import and use Shearlock one`s
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.Menu;
I hit this problem as well, and was already importing the actionbarsherlock menu and menuitem libraries.
What did the trick for me was adding the following to the onOptionsItemSelected function so the relevant toggle function was called when the home button action was triggered...
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId())
{
case android.R.id.home:
getSlidingMenu().toggle();
return true;
...
}
return super.onOptionsItemSelected(item);
}

Categories

Resources