android- menu settings customization - java

i added settings option in android menu. it works fine while testing in emulator. but when i try in device it wont change.. can i know what is the problem? Do i need to change anything in androidmanifest.xml file.
following is my code:
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
menu.add(1,1,0,"Settings").setIcon(R.drawable.ic_tab_settings_grey);
setMenuBackground();
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch(item.getItemId())
{
case 1:
Intent in = new Intent(TransactionSummaryActivity.this, WelcomePage.class);
startActivity(in);
finish();
return true;
default:
return true;
}
}
protected void setMenuBackground(){
getLayoutInflater().setFactory( new Factory() {
#Override
public View onCreateView(String name, Context context, AttributeSet attrs) {
// TODO Auto-generated method stub
if ( name.equalsIgnoreCase( "com.android.internal.view.menu.IconMenuItemView" ) ) {
try { // Ask our inflater to create the view
LayoutInflater f = getLayoutInflater();
final View view = f.createView( name, null, attrs );
new Handler().post( new Runnable() {
public void run () {
view.setBackgroundResource(R.drawable.menu_selector);
// view.setBackgroundColor(Color.parseColor("#257CB5"));
((TextView) view).setTextColor(Color.WHITE);
}
} );
return view;
}
catch (InflateException e) {}
catch (ClassNotFoundException e) {}
}
return null;
}
});
}

i was just seeing if your phones api level was lower then what you have the applications set to. I believe that if it works on the emulator,but doesnt work on your device, i don't think thats a coding problem.
Delete all traces of the app on your phone. "Uninstall" it. Then try running the app again, It should work.

Related

How can convert ListActivity to AppCompatActivity

I want to change my activity parent from ListActivity to AppCompatActivity, because I need to use check permission Granted and it's need AppCompat, but my activity is ListView.
I try this action, but not received a good result :(
This is my source code (Ever has ... is for no added code):
public class RingtoneSelectActivity extends ListActivity {
...
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
mShowAll = false;
String status = Environment.getExternalStorageState();
if (status.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
showFinalAlert(getResources().getText(R.string.err_sdcard_readonly));
return;
}
if (status.equals(Environment.MEDIA_SHARED)) {
showFinalAlert(getResources().getText(R.string.err_sdcard_shared));
return;
}
if (!status.equals(Environment.MEDIA_MOUNTED)) {
showFinalAlert(getResources().getText(R.string.err_no_sdcard));
return;
}
Intent intent = getIntent();
mWasGetContentIntent = intent.getAction().equals(
Intent.ACTION_GET_CONTENT);
// Inflate our UI from its XML layout description.
setContentView(R.layout.media_select);
SplashHandler mHandler = new SplashHandler();
Message msg = new Message();
//Assign a unique code to the message.
//Later, this code will be used to identify the message in Handler class.
msg.what = 0;
// Send the message with a delay of 3 seconds(3000 = 3 sec).
mHandler.sendMessageDelayed(msg, 10000);
try {
mAdapter = new SimpleCursorAdapter(
this,
// Use a template that displays a text view
R.layout.media_select_row,
// Give the cursor to the list adatper
createCursor(""),
// Map from database columns...
new String[]{
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media._ID},
// To widget ids in the row layout...
new int[]{
R.id.row_artist,
R.id.row_album,
R.id.row_title,
R.id.row_icon,
R.id.row_options_button});
setListAdapter(mAdapter);
getListView().setItemsCanFocus(true);
// Normal click - open the editor
getListView().setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent,
View view,
int position,
long id) {
startRingdroidEditor();
}
});
} catch (SecurityException e) {
// No permission to retrieve audio?
Log.e("Ringtone", e.toString());
// todo error 1
} catch (IllegalArgumentException e) {
// No permission to retrieve audio?
Log.e("Ringtone", e.toString());
// todo error 2
}
mAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
public boolean setViewValue(View view,
Cursor cursor,
int columnIndex) {
if (view.getId() == R.id.row_options_button) {
// Get the arrow image view and set the onClickListener to open the context menu.
ImageView iv = (ImageView) view;
iv.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
openContextMenu(v);
}
});
return true;
} else if (view.getId() == R.id.row_icon) {
setSoundIconFromCursor((ImageView) view, cursor);
return true;
}
return false;
}
});
// Long-press opens a context menu
registerForContextMenu(getListView());
}
}
...
}
I changed to this:
public class RingtoneSelectActivity extends AppCompatActivity {
But I received some errors in this lines:
...
setListAdapter(mAdapter);
getListView().setItemsCanFocus(true);
getListView().setOnItemClickListener(new OnItemClickListener() { ... });
...
registerForContextMenu(getListView());
My errors:
Cannot resolve method 'setListAdapter(android.widget.SimpleCursorAdapter)
Cannot resolve method 'getListView()'
How can I fix that errors?
[Edit]
My LogCat:
E/ACRA: ACRA caught a NullPointerException for ir.ari.mp3cutter
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.SimpleCursorAdapter.changeCursor(android.database.Cursor)' on a null object reference
at ir.ari.mp3cutter.RingtoneSelectActivity.refreshListView(RingtoneSelectActivity.java:621)
at ir.ari.mp3cutter.RingtoneSelectActivity.onOptionsItemSelected(RingtoneSelectActivity.java:314)
at android.app.Activity.onMenuItemSelected(Activity.java:2908)
at com.android.internal.policy.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1151)
at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:761)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:904)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:894)
at com.android.internal.view.menu.MenuPopupHelper.onItemClick(MenuPopupHelper.java:200)
at android.widget.AdapterView.performItemClick(AdapterView.java:310)
at android.widget.AbsListView.performItemClick(AbsListView.java:1145)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3042)
at android.widget.AbsListView$3.run(AbsListView.java:3879)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Line 304 to 319:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_about:
RingtoneEditActivity.onAbout(this);
return true;
case R.id.action_record:
onRecord();
return true;
case R.id.action_show_all_audio:
mShowAll = true;
refreshListView();
return true;
default:
return false;
}
}
And line 619 to 622:
private void refreshListView() {
String filterStr = mFilter.getQuery().toString();
mAdapter.changeCursor(createCursor(filterStr));
}
[notice: I'm sorry for my bad talking, because I not learned English as good :)
So don't change super class, Just check for ungranted permissions with ContextCompat.checkSelfPermission() and then request Permission by ActivityCompat.requestPermissions() and get the result in:
#Override
public void onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
}

Stop focus on EditText when keyboard is hidden

I'm from iOS development and new in Android app making, something looks really strange to me in Android, why EditText stay focused when keyboard is hidden ??
I've tried to set a OnFocusChangeListener on my EditText but this is not working when the keyboard hide, the listener isn't called.
I've also tried to detect keyboard hiding with a onChangeListener but it doesn't work.. (only with hard keyboard apparently).
#Override
public void onFocusChange(View v, boolean hasFocus) {
// not called when keyboard hides
}
});
I've been looking for a while and I only found answer for stopping focus at first launch but that's not what I'm looking for..
Thanks
Okay, kind of this
private void setUpEtxFocusListener() {
etx.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean hasFocus) {
if (hasFocus) {
if ((LOG_DEBUG)) Log.d(TAG, "etx : GOT Focus");
} else {
if ((LOG_DEBUG)) Log.d(TAG, "etx : LOST Focus");
}
}
});
and when clicked outside, etx will lose focus and you hide the keyboard
//this will trigger etx setOnFocusChangeListener - onFocus change() - NO FOCUS clause
#Override
public boolean dispatchTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
View v = getCurrentFocus();
if (v instanceof EditText) {
Rect outRect = new Rect();
v.getGlobalVisibleRect(outRect);
if (!outRect.contains((int) event.getRawX(), (int) event.getRawY())) {
v.clearFocus();
// just an utility class to hide.
UtilExtra.hideKeyboard(this);
}
}
}
return super.dispatchTouchEvent(event);
}
Try this:
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
you can simply use this code and your focus will be gone
editText.clearFocus();
To catch keyboard's open/close event use this code:
//...
private int layoutSize = 0;
private boolean isKeyboardVisible = false;
//...
#Override
public void onCreate(Bundle savedInstanceState) {
setKeyboardOpenListener();
}
//...
private void setKeyboardOpenListener() {
View activityRootView = findViewById(android.R.id.content);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
if (activityRootView.getHeight() + Util.getStatusBarHeight(this) >= layoutSize) {
layoutSize = activityRootView.getHeight();
if (isKeyboardVisible) {
isKeyboardVisible = false;
onKeyboardClose();
}
} else {
if (!isKeyboardVisible) {
isKeyboardVisible = true;
onKeyboardOpen();
}
}
});
}
//...
public static int getStatusBarHeight(Context context) {
int result = 0;
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
Use editText.clearFocus() and editText.setCursorVisible(false) both methods, It may helps you.

How to use a MediaPlayer Singleton

I am new to Android developing and am starting with a simple soundboard application. I started developing a soundboard using multiple fragments until I realized that I was using multiple instances of MediaPlayer. This is not good because I want only one sound to play at a time.
I realized that I'd have to use a MediaPlayer Singleton to solve my problem. The only problem is that I can't find many sources or examples of the MediaPlayer Singleton online.
Here's what I originally put into every "onCreateView" in each fragment:
public static class FragmentPage1 extends Fragment {
int selectedSoundId;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_page1, container, false);
final MediaPlayer player = new MediaPlayer();
final Resources res = getResources();
final int[] buttonIds = { R.id.btn1, R.id.btn2, R.id.btn3, R.id.btn4, R.id.btn5, R.id.btn6, R.id.btn7, R.id.btn8, R.id.btn9 };
final int[] soundIds = { R.raw.sound01, R.raw.sound02, R.raw.sound03, R.raw.sound04, R.raw.sound05, R.raw.sound06, R.raw.sound07, R.raw.sound08, R.raw.sound09 };
View.OnClickListener listener = new View.OnClickListener() {
#Override
public void onClick(View v) {
for (int i = 0; i < buttonIds.length; i++) {
if (v.getId() == buttonIds[i]) {
selectedSoundId = soundIds[i];
AssetFileDescriptor afd = res.openRawResourceFd(soundIds[i]);
player.reset();
try {
player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
player.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
player.start();
break;
}
}
}
};
for (int i = 0; i < buttonIds.length; i++) {
ImageButton soundButton = (ImageButton) rootView.findViewById(buttonIds[i]);
registerForContextMenu(soundButton);
soundButton.setOnClickListener(listener);
}
return rootView;
}
}
To my knowledge I'd probably put the onClickListener inside of each fragment and the MediaPlayer Singleton in a new Java class. I don't know what to do from there though.
How do I implement a MediaPlayer Singleton and how do I call it back in the fragment's "onCreateView" method?
Examples are highly appreciated and thanks!
See, Singleton is a design pattern, and it is implemented by setting the default constructor as private, then you should provide a get method from wich you can recover your object instance. Check out the example bellow:
public class Foo {
private MediaPlaye md;
private Foo () {
md = new MediaPlayer();
}
public MediaPlayer getMediaPlayer () {
if (md == null) {
new Foo();
}
return md;
}
}
In your sittuation, the best thing to do is to create a Service class that will encapsulate all the MediaPlayer methods. This is done like that because, usually, the developer wants that the player keeps playing even if the user leaves the Activity to which it is binded. In each fragment that you want to use the MediaPlayer API, you can bind the Service and use the defined interface. Take a look in the class below:
public class MusicPlayerService extends android.app.Service implements MediaPlayer.OnPreparedListener,
MediaPlayer.OnErrorListener,
MediaPlayer.OnCompletionListener,
ObserverSubject {
private static final int NOTIFY_ID = 1;
private List<MusicPlayerObserver> mObservers;
private MediaPlayer mMediaPlayer;
private final IBinder playerBind = new MusicBinder();;
private List<Track> mPlaylist;
private Integer mPosition;
private Boolean isRepeating;
private Boolean isShuffling;
private Boolean isPrepared;
private Boolean isPaused;
// Callback Methods______________________________________________
#Override
public void onCreate() {
...
}
#Override
public void onPrepared(MediaPlayer mp) {
...
}
#Override
public IBinder onBind(Intent intent) {
return playerBind;
}
#Override
public boolean onUnbind(Intent intent) {
mMediaPlayer.stop();
mMediaPlayer.release();
return false;
}
#Override
public void onDestroy() {
stopForeground(true);
}
#Override
public boolean onError(MediaPlayer mp, int what, int extra) {
mp.reset();
return false;
}
// UTIL METHODS__________________________________________________
private Long getCurrentTrackId() {
return mPlaylist.get(mPosition).getTrackId();
}
private Long getCurrentAlbumId() {
return mPlaylist.get(mPosition).getAlbumId();
}
// MEDIA PLAYER INTERFACE________________________________________
public void play() {
...
}
public void pause() {
...
}
public void resume() {
...
}
public void next() {
...
}
public void previous() {
...
}
public void seekTo(int pos) {
...
}
// SERVICE INTERFACE PROVIDER_____________________________________
/**
* Interface through the component bound to this service can interact with it
*/
public class MusicBinder extends Binder {
public MusicPlayerService getService() {
return MusicPlayerService.this;
}
}
}
I highly recommend that you follow this strategy of creating a MusicPlayer service. Also, I suggest you to take a look in another Design Patter called Observer. Usually, in music apps, you want to update several UI elements based on the MP state. Observer is perfect for that situation.
Hope I've helped a little.

Disable contextual selection menu in crosswalk (cordova)

I wish to disable the native contextual menu that is shown when you select some text, the one with the select all, copy, share and search buttons. I do not however want to disable selections themselves. Ideally I would wish to extend the menu actually, but honestly, I am more than perfectly fine with just disabling it. With textfields and the like it tends to be relatively simple from the documentation I found, but I just can't figure out a way to make this work with XWalkView/CordovaWebView. Might be that I am just searching in entirely the wrong corner though.
I have a workaround.
For WebView there is a solution, but it doesn't work for XWalkView:
WebView selection menu workaround
My gradle includes compile 'org.xwalk:xwalk_core_library:14.43.343.17'
My solution, the main idea in the onAttachedToWindow method:
public class XWalkWebView extends XWalkView {
public XWalkWebView(Context context, AttributeSet attrs) {
super(context, attrs);
}
private ActionMode.Callback mOriginalCallback;
#Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
try {
View innerChild = ((ViewGroup) getChildAt(0)).getChildAt(0);
Field contentViewField = innerChild.getClass().getDeclaredField("mContentView");
contentViewField.setAccessible(true);
XWalkContentView xWalkContentView = (XWalkContentView) contentViewField.get(innerChild);
Field contentViewCoreField = xWalkContentView.getClass().getSuperclass().getDeclaredField("mContentViewCore");
contentViewCoreField.setAccessible(true);
ContentViewCore viewCore = (ContentViewCore) contentViewCoreField.get(xWalkContentView);
viewCore.setContainerView(this);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}
#Override
public ActionMode startActionMode(ActionMode.Callback callback) {
mOriginalCallback = callback;
ActionMode.Callback c = new // your callback...
return super.startActionMode(c);
}
}
I try Warabei's solution but it not work on 15.44.384.13. I improve to find ContentViewCore cross versions:
public class XWalkWebView extends XWalkView {
...
private Field getFields(Class clazz){
for(Field field:clazz.getDeclaredFields()){
if(ContentViewCore.class == field.getType()){
return field;
}
}
clazz = clazz.getSuperclass();
if(clazz!=null && clazz!=Object.class){
Field field = getFields(clazz);
if(field!=null)return field;
}
return null;
}
private void inject(View view){
Field field = getFields(view.getClass());
if(field!=null){
field.setAccessible(true);
try {
ContentViewCore viewCore = (ContentViewCore) field.get(view);
viewCore.setContainerView(this);
return;
}catch(Exception e){
}
}
if(view instanceof ViewGroup){
ViewGroup viewGroup = (ViewGroup)view;
int count = viewGroup.getChildCount();
for(int i = 0;i<count;i++){
inject(viewGroup.getChildAt(i));
}
}
}
#Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
inject(this);
}
...
To disable contextual selection menu:
#Override
public ActionMode startActionMode(ActionMode.Callback callback) {
return new ActionMode() {
#Override
public void setTitle(CharSequence charSequence) {
}
#Override
public void setTitle(int i) {
}
#Override
public void setSubtitle(CharSequence charSequence) {
}
#Override
public void setSubtitle(int i) {
}
#Override
public void setCustomView(View view) {
}
#Override
public void invalidate() {
}
#Override
public void finish() {
}
#Override
public Menu getMenu() {
return null;
}
#Override
public CharSequence getTitle() {
return null;
}
#Override
public CharSequence getSubtitle() {
return null;
}
#Override
public View getCustomView() {
return null;
}
#Override
public MenuInflater getMenuInflater() {
return null;
}
};
}
It is an old post but I haven't been able to find another solution.
A simple workaround to disable context options in crosswalk view..
Go to your crosswalk project into res/menu/select_action_menu.xml
Delete or comment on the item you don't want to show
Save, build and run
This CSS should prevent context menus in both Android and IOS, as given in the cordova template
* {
-webkit-tap-highlight-color: rgba(0,0,0,0); /* make transparent link selection, adjust last value opacity 0 to 1.0 */
}
body {
-webkit-touch-callout: none; /* prevent callout to copy image, etc when tap to hold */
-webkit-text-size-adjust: none; /* prevent webkit from resizing text to fit */
-webkit-user-select: none; /* prevent copy paste, to allow, change 'none' to 'text' */
}

Android: How to show context menu of activity while keeping soft keyboard shown

I would like to show the context menu of my activity while keeping the soft keyboard shown. Here is my code in creating menu for my main activity:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
boolean result = super.onCreateOptionsMenu(menu);
MenuItem m = menu.add(0, LOGIN_MENU_ITEM, 0, "Login");
m.setIcon(android.R.drawable.ic_menu_preferences);
m = menu.add(0, CONFIGURE_MENU_ITEM, 0, R.string.menu_settings);
m.setIcon(android.R.drawable.ic_menu_preferences);
m = menu.add(0, EXIT_MENU_ITEM, 0, R.string.menu_exit);
m.setIcon(android.R.drawable.ic_menu_close_clear_cancel);
m = menu.add(0, ABOUT_MENU_ITEM, 0, R.string.menu_about);
m.setIcon(android.R.drawable.ic_menu_info_details);
return result;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
boolean result = super.onOptionsItemSelected(item);
Intent intent = null;
switch (item.getItemId()) {
case ABOUT_MENU_ITEM:
if (m_AlertDlg != null)
{
m_AlertDlg.cancel();
}
final SpannableString s = new SpannableString(getString(R.string.about).replace("\\n","\n").replace("${VERSION}", getVersion(this)));
Linkify.addLinks(s, Linkify.WEB_URLS);
m_AlertDlg = new AlertDialog.Builder(this)
// .setMessage(getString(R.string.about).replace("\\n","\n").replace("${VERSION}", getVersion(this)))
.setMessage(s)
.setTitle(getString(R.string.menu_about))
.setIcon(R.drawable.icon22_click)
.setCancelable(true)
.show();
((TextView)m_AlertDlg.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
break;
case EXIT_MENU_ITEM:
on(this,false);
// final Boolean exit_rem = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Settings.PREF_REMEMBER, false);
// if (!exit_rem){
// Editor edit = PreferenceManager.getDefaultSharedPreferences(this).edit();
// edit.putString(Settings.PREF_USERNAME, "");
// edit.putString(Settings.PREF_PASSWORD, "");
// edit.commit();
// }
Receiver.pos(true);
Receiver.engine(this).halt();
Receiver.mSipdroidEngine = null;
Receiver.reRegister(0);
stopService(new Intent(this,RegisterService.class));
finish();
break;
case CONFIGURE_MENU_ITEM:
try {
intent = new Intent(this, org.sparksoftsip.sipua.ui.Settings.class);
startActivity(intent);
} catch (ActivityNotFoundException e) {
}
break;
case LOGIN_MENU_ITEM:
LoginScreen();
break;
}
return result;
}
In my main activity, I've built a custom AutoCompleteTextView, wherein it receives focus on start. I listen to key presses here, and plans to open the context menu by listening to the menu button. However nothing is happening to my current code:
public class InstantAutoCompleteTextView extends AutoCompleteTextView {
public InstantAutoCompleteTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
#Override
public void onWindowFocusChanged(boolean hasWindowFocus) {
super.onWindowFocusChanged(hasWindowFocus);
}
private Activity getActivity() {
Context context = getContext();
if (context instanceof Activity) {
return (Activity) context;
} else {
return null;
}
}
#Override
public boolean enoughToFilter() {
return true;
}
#Override
public boolean dispatchKeyEventPreIme(KeyEvent event)
{
Activity activity = getActivity();
if (KeyEvent.KEYCODE_BACK == event.getKeyCode() && event.getAction () == KeyEvent.ACTION_DOWN)
{
Log.v("", "Back Pressed");
activity.onBackPressed();
//Want to call this method which will append text
//init();
}
if (KeyEvent.KEYCODE_MENU == event.getKeyCode() && event.getAction () == KeyEvent.ACTION_DOWN)
{
Log.e("hello", event.toString());
activity.openContextMenu(activity.getWindow().getDecorView().findViewById(android.R.id.content));
}
return true;
//return super.dispatchKeyEventPreIme(event);
}
}
I have tried using
openContextMenu(activity.getWindow().getDecorView().findViewById(android.R.id.content))
however, nothing is happening. I have also tried (activity.findViewById(android.R.id.content)) and (activity.findViewById(android.R.id.content).getViewRoot()), but nothing shows up. How do I remedy this?
It looks I made a foolish mistake. I did not use a context menu, but rather an options menu. So, the code for my on key press should be
openOptionsMenu()
instead of using
openContextMenu(View)

Categories