menu is not coming on top right side corner - android

In virtual mobile menu is displaying.But it is not displaying in my personal mobile.I have kept mainactivity.java ,main.xml,androidmainfest.xml files here.Any answers please...
//mainactivity.java
public class MainActivity extends Activity{
String username,password; ResultSet rs =null;
boolean temcfag=false;
static boolean temqfag=true;
public static String tag="Lifecycle activity";
EditText user,pass;
AlertDialog.Builder dialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dialog=new AlertDialog.Builder(this);
dialog.setNeutralButton("OK", null);
user=(EditText)findViewById(R.id.editText1);
pass=(EditText)findViewById(R.id.editText2);
final Button click=(Button)findViewById(R.id.button2);
click.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
Intent launchactivity= new Intent(MainActivity.this,com.example.desisquarea.LoginActivity.class);
startActivity(launchactivity);
}
});
}
#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;
}
}
//menu/main.xml
<?xml version="1.0" ?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/login" android:title="SignUP" />
<item android:id="#+id/sign" android:title="Login" />
<item android:id="#+id/home" android:title="Home" />
</menu>
//androidmainfest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.desisquarea"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.desisquarea.MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

LayoutParams lp = dialog.getWindow().getAttributes();
lp.gravity = Gravity.TOP | Gravity.RIGHT;
myDialog.getWindow().setAttributes(lp);
dialog.show();

Related

Unable to see menu in action bar Android

i have problem putting the menu in the upper right corner. even i checked this Link. but not worked.
i have tried with android:showAsAction="always"even tried with more then 6 SDK version but not worked .
manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name">
<activity
android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
items.xml:-
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/phone"
android:title="#string/phone"
android:icon="#drawable/phone"
android:showAsAction="always"
/>
<item
android:id="#+id/computer"
android:title="#string/computer"
android:icon="#drawable/computer"
/></menu>
Java:-
public class MainActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.items, menu);
//inflater.inflate(R.menu.items, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch(item.getItemId()){
case R.id.phone:
Toast.makeText(getBaseContext(), "You selected Phone", Toast.LENGTH_SHORT).show();
break;
case R.id.computer:
Toast.makeText(getBaseContext(), "You selected Computer", Toast.LENGTH_SHORT).show();
break;
}
return true;
}
}
.
please suggest . any suggestion are welcome . Thanks
Solution as below-
In build.gradle(Module:app) add appcompat dependency
dependencies {
compile 'com.android.support:appcompat-v7:23.1.1'
// ... other dependencies
}
change
public class MainActivity extends Activity
to
public class MainActivity extends AppCompatActivity.
change your menu.xml file as below
<?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/phone"
android:title="#string/phone"
android:icon="#drawable/phone"
app:showAsAction="always" />
<item
android:id="#+id/computer"
android:title="#string/computer"
android:icon="#drawable/computer" />
</menu>

How to display menu options in android?

I am having trouble displaying my menu options on my phone. I got all the code right I think but it is not displaying. Any help would be greatly appreciated.
Here is how my manifest looks like:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.drumloopsequencer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:screenOrientation="landscape"
android:name=".Main"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here is the onCreateOptionsMenu function:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.mymenu, menu);
return true;
}
and here is the menu xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/file"
android:title="#string/fileTab"
android:orderInCategory="1"
android:showAsAction="ifRoom"
/>
<item
android:id="#+id/packs"
android:title="#string/packsTab"
android:orderInCategory="2"
android:showAsAction="ifRoom"
/>
<item
android:id="#+id/drumRack"
android:title="#string/drumRackTab"
android:orderInCategory="3"
android:showAsAction="ifRoom"
/>
</menu>
If you are using a fragment make sure that you have enabled the options menu with setHasOptionsMenu(true). A good place to call this might be from onCreate.
public class MyFragment extends Fragment {
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
}
or for an Activity
public class MyActivity extends Activity {
#Override
public boolean onCreateOptionsMenu(Menu menu){
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.mymenu, menu);
return true;
}
}
Try this :
#Override
public void onAttachedToWindow() {
super.onAttachedToWindow()
openOptionsMenu();
};
If you are using fragment then you have to do this:
//inside constructor
public MyClassFrag(){
setHasOptionsMenu(true);
}
or inside onCreate()
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}

None of the action buttons are showing up on action bar

I am following the guild on developer.android.com and have made it to the part to adding action button to the bar. None of them, however, are wanting to show up. I have looked through the code, did research, and even redid the whole project just the make sure I was following everything right. Nothing I do seems to work so I thought I would put it here and let a fresh (and more experience) set of eyes look at it and let me where I am going wrong.
main_activity_actions.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myfirstapp="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
myfirstapp:showAsAction="ifRoom" />
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
myfirstapp:showAsAction="never" />
</menu>
DisplayMessageActivity.java
public class DisplayMessageActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
setContentView(textView);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
setContentView(R.layout.activity_main);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity_actions, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_search:
//openSearch();
return true;
case R.id.action_settings:
//openSettings();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light.DarkActionBar" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>
</application>
</manifest>
screenshot
Just remove the setContentView(R.layout.activity_main);inside
#Override
public boolean onCreateOptionsMenu(Menu menu) {
setContentView(R.layout.activity_main);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity_actions, menu);
return super.onCreateOptionsMenu(menu);
}
and also add return true instead of return super.onCreateOptionsMenu(menu);
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_activity_actions, menu);
return true;
}
try this. Its working for me.

WebView error force close application

This is my code, I'm trying to load the parsed data from RSS feed. But I test my app using google.com only, and there's an error.
public class WebsiteOpen extends Activity {
WebView web;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_website_open);
Intent intent = getIntent();
String message = intent.getStringExtra("rss-url");
web = (WebView) findViewById(R.id.webView1);
web.getSettings().setJavaScriptEnabled(true);
web.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
Toast.makeText(WebsiteOpen.this, description,
Toast.LENGTH_SHORT).show();
}
});
web.loadUrl("http://google.com");
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.website_open, menu);
return true;
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
web.saveState(outState);
}
#Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
web.restoreState(savedInstanceState);
}
}
This is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.itcuties.multicategoryrssreader"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_dilc"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.itcuties.multicategoryrssreader.RssTabsActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.itcuties.multicategoryrssreader.RssChannelActivity" />
<activity android:name="com.itcuties.multicategoryrssreader.Upfm" />
<activity
android:name="com.itcuties.multicategoryrssreader.listeners.WebsiteOpen"
android:label="#string/title_activity_website_open"
android:configChanges="orientation|screenSize" >
</activity>
</application>
</manifest>
help me please. thank you.
I think you can replace the code of Intent and message with this:
Bundle bundle = getIntent().getExtras();
String message = "";
try{
message = bundle.getString("rss-url"");
}catch(nullpointerException e){
//System.out.println("No String Extra");
}
However, i think the following code is useless. It's should be removed instead.
Intent intent = getIntent();
String message = intent.getStringExtra("rss-url");
If it doesn't work, make sure that the id "webView1" is included in the layout "activity_website_open.xml".

Android - Spinning circle appears in Action Bar

So I have an action bar I am trying to learn and when I implement it I see this white spinning circle left of my first menu item. Why is this being shown here?
Source:
package com.example.lookingfor;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.Window;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch (item.getItemId()) {
case R.id.atcAbout:
break;
case R.id.atcContact:
break;
case R.id.atcRate:
break;
}
return true;
}
}
Menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/atcAbout"
android:showAsAction="ifRoom"
android:title="About"/>
<item
android:id="#+id/atcRate"
android:showAsAction="ifRoom"
android:title="Rate this app"/>
<item
android:id="#+id/atcContact"
android:showAsAction="ifRoom"
android:title="Contact Us"/>
</menu>
Main Layout
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lookingfor"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here is a screenshot (I cannot post images here yet)
http://imgur.com/RaTTP
How can I get rid of this spinning circle before I publish the app? It is an ugly and annoying distraction to the app itself.
Thanks Y'all!
Try commenting out the line requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); in your onCreate() callback.

Categories

Resources