I am developing an app, and in that app have 3 activities
Login
Main
PhotoViewer extends fragmentActivity
in the manifest:
<activity
android:name=".PhotoViewerActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/title_activity_photo_viewer"
android:parentActivityName=".MainActivity"
android:theme="#style/FullscreenTheme" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.ceiva.snap.MainActivity" />
</activity>
Can someone please advice me how to add "Customizer" text to the right of the actionbar for just the PhotoViewerActivity.
Also I tried doing this:
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setDisplayShowTitleEnabled(true);
// getActionBar().setIcon(android.R.color.transparent);
getActionBar().setTitle("Back");
Log.i(TAG, "actionbar " + getActionBar().isShowing());
ActionBar actionBar = getActionBar();
TextView customizerView = new TextView(getApplicationContext());
customizerView.setEnabled(true);
customizerView.setVisibility(View.VISIBLE);
customizerView.setText(getString(R.string.action_customizer));
customizerView.setTextSize(16);
customizerView.setPadding(100, 40, 40, 40);
actionBar.setCustomView(customizerView);
the back title shows up on the left side but the textview doesnt show up.
You can try with this
1.Create xml file in menu folder
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#+id/action_customize"
android:icon="#drawable/ic_action_customize"
android:title="#string/action_customize"
android:showAsAction="ifRoom"/>
</menu>
2.In your activity
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.activity_main_actions, menu);
return super.onCreateOptionsMenu(menu);
}
3.You can set actions for your menu item with
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Take appropriate action for each action item click
switch (item.getItemId()) {
case R.id.action_customize:
// DO STUFF
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Related
I have a requirement that action Overflow menu icon should show in fragment, but not activity.
Code:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.filter:
openFilterDialog();
return true;
default:
break;
}
return false;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_mail_list, menu);
return true;
}
menu xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.dwisehealthcare.pmstablet.consult.activity.ConsultActivity">
<item
android:id="#+id/filter"
android:title="Filter"
android:icon="#drawable/ic_baseline_filter_list_24"
app:showAsAction="always" />
</menu>
I searched, but everyone is talking about menu item, not action icon.
Try this link may be it will help you, with the help of this you can add menu anywhere you want.Just add an ImageView to that fragment and when you click that imageView you create a PopUpMenu
well the problem is that my icon of my option add item on the action bar does not appear(it has space for show the icon but it does not). my option just appear on the dropdown menu (the 3 points XD) thanks you. here is my code xml then my code java:
<?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/menuAddItem"
android:title="Add Item"
android:icon="#android:drawable/ic_menu_add"
app:showAsAction="ifRoom"
/>
</menu>
java:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.clear();
MenuInflater infladorMenu = new MenuInflater(this);
infladorMenu.inflate(R.menu.menu,menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.menuAddItem:
this.listaDatos.add("Dato AƱadido");
this.adaptador.notifyDataSetChanged();
break;
}
return super.onOptionsItemSelected(item);
}
As you can see the icon does not appear but the actionbar has space
As you can see the icon does not appear but the actionbar has space, my option is just showed in the dropdown menu. thank you for your help.
I'm using actionBar and searchView, and this is my code:
public class MainActivity extends FragmentActivity {
#Override
public void onCreate(Bundle savedBundle) {
super.onCreate(savedBundle);
setContentView(R.layout.main_layout);
setupImageLoader();
setupSlidingMenu();
}
....
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options_menu, menu);
return true;
}
}
and my menu file is:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/search"
android:icon="#drawable/ic_search"
android:showAsAction="collapseActionView|ifRoom"
android:actionViewClass="android.widget.SearchView"/>
</menu>
Now what I see is this:
When not selected the SearchView is on the bottom of the screen, and it becames part of the actionbar only when active. How can I embed it like in Play store?
From your java-code, it seems that you are using FragmentActivity and thus the android-support library. But your selected SearchView-class is from the native Android framework.
Look at the developer-docs to see how it should be done:
http://developer.android.com/guide/topics/ui/actionbar.html#ActionView
Also, it seems you have the splitActionbar enabled, or else your search-button would appear in the upper actionbar. So check your AndroidManifest.xml for something like this:
<activity uiOptions="splitActionBarWhenNarrow" ... >
<meta-data android:name="android.support.UI_OPTIONS"
android:value="splitActionBarWhenNarrow" />
</activity>
I'm implementing action bar with items. I can't see the selected item effect (background selection color) when I click on an item in the actions :
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#+id/menu_item_share_action_provider_action_bar"
android:showAsAction="always"
android:title="TTTTTTT"
android:checkable="true"
/>
<item android:id="#+id/menu_item_share_action_provider_action_bar"
android:showAsAction="always"
android:title="AAAAAA"
android:checkable="true"
/>
</menu>
On My SherlockActivity :
#Override
public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
UPDATE:
You need to do something like this (switching the icons ids):
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// app icon in action bar clicked; go home
Intent intent = new Intent(this, HomeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
-----------
Have you done something like this:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}
This is needed to inflate the XML file.
Maybe setting identical id's on both items is causing the problem. Did you try to change one of them?
Well this is my code:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.news:
Intent j = new Intent(MainScreen.this,LatestNewsScreen.class);
startActivity(j);
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
this is my manifest lines I added:
<activity android:name=".LatestNewsScreen"
> </activity>
and i the latestNewsScreen I must see an simple textView. I press menu and if I click nothing happens. Why Is that?
this is my menu.xml code:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/news"
android:icon="#drawable/icon"
android:title="About us" />
</menu>
Any help?
When you click menu, you should see the menu items (in this case just the one) appear at the bottom of the screen. When you click that item then your other activity should start.
Maybe your icon is not the right size, try changing it to the system one, like
android:icon="#android:drawable/ic_menu_info_details"
and see what happens