I am using option menu, i want to increase the size of my icon...
means icon are too small... how can increase their width or height ....
or how remove space around icon.. i.e padding, margin etc...
i want a menu with icon at bottom...
what i should do???
<activity
android:name="com.example.parentengagementtracking.BaseActivity"
android:label="#string/title_activity_base"
android:theme="#style/MenuTheme" >
<!-- android:theme="#style/Theme.FixedSize"> -->
</activity>
<style name="MenuTheme" parent="android:Theme">
<item name="android:panelFullBackground">#drawable/back11</item>
<item name="android:padding">1dip</item>
<item name="android:drawablePadding">1dip</item>
</style>
public class BaseActivity extends Activity {
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_parent_home, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
Bundle objBundle;
Intent objIntent;
switch (item.getItemId())
{
case R.id.menu_about_us:
objIntent=null;
objIntent = new Intent(BaseActivity.this,InfoActivity.class);
objBundle=new Bundle();
objBundle.putString("source","BaseActivity");
objIntent.putExtras(objBundle);
finish();
startActivity(objIntent);
return true;
case R.id.menu_profile:
objIntent=null;
objIntent = new Intent(BaseActivity.this,UserProfile.class);
finish();
startActivity(objIntent);
return true;
case R.id.menu_activity:
objIntent=null;
objIntent = new Intent(BaseActivity.this,ViewActivity.class);
finish();
startActivity(objIntent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
<!-- android:icon="#drawable/homen" -->
<item
android:id="#+id/menu_profile"
android:orderInCategory="2"
android:showAsAction="always"
android:icon="#drawable/profile1"
android:title="Profile"/>
<item
android:id="#+id/menu_activity"
android:orderInCategory="3"
android:showAsAction="always"
android:icon="#drawable/reports"
android:title="Reports"/>
<item
android:id="#+id/menu_about_us"
android:icon="#drawable/aboutusn"
android:orderInCategory="4"
android:showAsAction="always"
android:title="Aboutus"/>
how can i set padding, margin, width and height etc of icon..??
Your image should be 24*24 or 36*36.
You can solve this problem by using "app:actionLayout".
<item
android:id="#+id/menu1"
app:actionLayout="#layout/custom_action_bar" //this line will change icon
android:visible="true"
android:title="Menu 1"
app:showAsAction="always" />
Refer this docs Custom menu icons to add listeners to custom menu.
Related
I want to remove that 3 dots from toolbar and also want to add an image with textview on that position.That image and textviews are different for each fragment activity.
Also can anyone tell me how to make the toolbar transparent.
In your MainActivity you will have optionmenu, just make it false
#Override
public boolean onCreateOptionsMenu(Menu menu) {
return false;
}
Remove this item from menu.
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
visibility=false
android:title="#string/action_settings"/>
1)your First Question about removing three dots (Aditya -Vyas )solved your prob
#Override
public boolean onCreateOptionsMenu(Menu menu) {
return false;
}
2) Now to put image view
Crate Menu Resource
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_submit"
android:title="#string/submit"
android:icon="#drawable/ask_price_back"
app:showAsAction="always" />
</menu>
Then declare onCrateOptionsMenu and onOptionsImtemSelected as below
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_submit, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_submit) {
//Your code to handle click
return true;
}
return super.onOptionsItemSelected(item);
}
3) Handling The menu from the fragment loaded in activity try this
override this method in your fragment
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
getActivity().getMenuInflater().inflate(R.menu.menu_of_fragment, menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_fragment) {
// Your code to handle Click
}
return super.onOptionsItemSelected(item);
}
1) From your menu.xml remove all items with tag .
This will remove three dots from your menu area.
2) Add a new item in your xml and give properties
android:icon="#drawable/image_you_want to show in the menu area"
app:showAsAction="always"
set your style like
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionOverflowButtonStyle">#style/MyActionButtonOverflow</item>
</style>
<!-- Style to replace actionbar overflow icon. set item 'android:actionOverflowButtonStyle' in AppTheme -->
<style name="MyActionButtonOverflow" parent="android:style/Widget.Holo.Light.ActionButton.Overflow">
<item name="android:src">#drawable/ic_launcher</item>
</style>
check this post : post
> for adding imageview and text
` <item android:id="#+id/action_cart"
android:icon="#drawable/cart2"
android:title="image"
app:showAsAction="always" />
<item
android:id="#+id/badge"
app:actionLayout="#layout/counter"
android:title="image"
android:icon="#drawable/shape"
app:showAsAction="always">
</item>`
In Layout counter
`<TextView
android:id="#+id/notif_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="20dp"
android:minHeight="20dp"
android:background="#drawable/shape"
android:text="0"
android:textSize="14sp"
android:textColor="#fff"
android:gravity="center"
android:padding="2dp"
android:singleLine="true">
</TextView>`
Just add this to you theme:
<item name="actionOverflowButtonStyle">#id/invisible</item>
I migrated my old Android (4.4 Kitkat) project from Eclipse to Android Studio.
When I run the app I have no ActionBar anymore!
Here is my main Activity class file:
public class Main extends Activity {
...
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
...
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent intent;
switch (item.getItemId()) {
case R.id.Open:
intent = new Intent(this, Open.class);
startActivity(intent);
return true;
case R.id.Email;
intent = new Intent(this, Email.class);
startActivity(intent);
return true;
case R.id.Compartir:
intent = new Intent(this, Compartir.class);
startActivity(intent);
return true;
case R.id.About:
intent = new Intent(this, About.class);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
Here is my styles.xml file:
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light"></style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionOverflowButtonStyle">#style/MyActionButtonOverflow</item>
</style>
<style name="MyActionButtonOverflow" parent="android:style/Widget.Holo.Light.ActionButton.Overflow">
<item name="android:src">#drawable/ic_action_expand</item>
<item name="android:background">?android:attr/actionBarItemBackground</item>
<item name="android:contentDescription">"Lala"</item>
</style>
</resources>
that I call from manifest file:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
In the project I have options.xml, as you can see it creates the content of the Action Bar: 1 buttons + the option button that is a dropdown menu with 3 buttons.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#+id/Open"
android:title="#string/option_open"
android:icon="#drawable/ic_action_open"
android:showAsAction="ifRoom" />
<item android:id="#+id/Email"
android:title="#string/option_email"
android:icon="#drawable/ic_action_person"
android:showAsAction="never" />
<item android:id="#+id/Compartir"
android:title="#string/option_compartir"
android:showAsAction="never" />
<item android:id="#+id/About"
android:title="#string/option_about"
android:showAsAction="never" />
</menu>
Anyway, if I build the app I get no ActionBar on my phone. I had it when I build the app with Eclipse ADT. I think the difference is the SDK old version that I used before. Then, how to make the ActionBar appears again with that custom theme?
I think you have to go back to Holo theme:
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
try this:
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
I made an Navigation-Drawer on the left and a menu on the right but my menu on the right (3 dots menu) is over the blue line...
I had the same problem with my Title text-view but i simply made his background-color transparent to fix it. Sadly i haven't been able to do the same with my menu.
Is there a way to make my menu background transparent or a work around to make my blue line go over it?
Here is how i made my menu:
MainActivity
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_view, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
// toggle nav drawer on selecting action bar app icon/title
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Menu options
switch (item.getItemId()) {
case R.id.map_view:
Toast.makeText(getApplicationContext(), "Map view pressed",
Toast.LENGTH_LONG).show();
//startActivity(GoogleMapsActivity.class);
return true;
case R.id.infrastucture_only:
Toast.makeText(getApplicationContext(),
"Infrastucture only pressed", Toast.LENGTH_LONG).show();
return true;
case R.id.infrastucture_map:
Toast.makeText(getApplicationContext(),
"Infrastucture + map pressed", Toast.LENGTH_LONG).show();
return true;
case R.id.camera_only:
Toast.makeText(getApplicationContext(), "Camera only pressed",
Toast.LENGTH_LONG).show();
return true;
case R.id.camera_infrastucture:
Toast.makeText(getApplicationContext(),
"Infrastucture + Camera pressed", Toast.LENGTH_LONG).show();
//startActivity(MetaioActivity.class);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
menu_view.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/dots_menu"
android:icon="#drawable/ic_action_overflow"
android:showAsAction="always"
android:title="#string/dots_menu">
<menu>
<item
android:id="#+id/map_view"
android:icon="#drawable/ic_action_map"
android:showAsAction="never"
android:title="#string/map"/>
<item
android:id="#+id/infrastucture_only"
android:showAsAction="never"
android:title="#string/infrastucture_only"/>
<item
android:id="#+id/infrastucture_map"
android:showAsAction="never"
android:title="#string/infrastucture_map"/>
<item
android:id="#+id/camera_only"
android:showAsAction="never"
android:title="#string/camera_only"/>
<item
android:id="#+id/camera_infrastucture"
android:showAsAction="never"
android:enabled="false"
android:title="#string/camera_infrastucture"/>
</menu>
</item>
</menu>
Thank you :)
I fixed the problem. I forgot to go to my style.xml file and add the transparency to my custom style like this:
<style name="MyActionBarStyle" parent="android:Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:icon">#android:color/transparent</item>
<item name="android:background">#android:color/transparent</item>
</style>
Now i don't know why when i open the menu it's not transparent
http://i821.photobucket.com/albums/zz140/miguel_melo_43/openWindow_zpse164f5b7.png
Is there a better way to make the menu so i can customize like i did with my navigation drawer?
http://i821.photobucket.com/albums/zz140/miguel_melo_43/NavDrawer_zpscaf04f64.png
Im building my top menu using the following code:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.menu_view, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.map_view:
Toast.makeText(getApplicationContext(), "Map view pressed",
Toast.LENGTH_LONG).show();
return true;
case R.id.camera_only:
Toast.makeText(getApplicationContext(), "Camera only pressed",
Toast.LENGTH_LONG).show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
menu_view.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/dots_menu"
android:icon="#drawable/ic_action_overflow"
android:showAsAction="always"
android:title="#string/dots_menu">
<menu>
<item
android:id="#+id/map_view"
android:icon="#drawable/ic_action_map"
android:showAsAction="never"
android:title="#string/map" />
<item
android:id="#+id/camera_only"
android:showAsAction="never"
android:title="#string/camera_only"/>
</menu>
</item>
</menu>
It happens that in my main activity i want to use this menu on top, but the menu appers transparent. Im using a fragment to display a full-screen map (google maps api v2), but then i can see the map under the top menu. I would like this fragment to "auto-resize" under the menu.
How can i set menu always on top of every activity?
So, i found out what my problem was!
in styles.xml file:
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#android:style/Theme.Holo">
<item name="android:windowActionBarOverlay">true</item>
</style> </resources>
i just needed to change the attribute windowActionBarOverlay to false, and it makes automatically the resize for the activity content.
For more details, here is the documentation
Okay, so I've been doing pretty well with developing my Android App but then I run into this issue. I tried to make another Menu Item to an Option Menu which I've never had problems with before but now, as described in the question, one of the items is showing up twice and another isn't showing up at all and then when I enter the Credits activity it crashes. Below is the codes for the res/menu/menu.xml And MainActivity.java (first one)
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu); return true; }
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.quit:
return true;
case R.id.new_game:
Intent intent = new Intent(this, New_Game.class);
startActivity(intent);
return true;
case R.id.visit_site:
Intent inten = new Intent(this, Site.class);
startActivity(inten);
return true;
case R.id.stay:
Intent inte = new Intent(this, MainActivity.class);
startActivity(inte);
return true;
case R.id.credits:
Intent i = new Intent(this, Credits.class);
startActivity(i);
return true;
case R.id.exit:
Intent in = new Intent(Intent.ACTION_MAIN);
in.addCategory(Intent.CATEGORY_HOME);
in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(in);
finish();
System.exit(0);
return true;
}return false;
}
Here is the XML Menu
<menu
xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/visit_site"
android:title="Visit the Medieval Site!" />
<item
android:id="#+id/quit"
android:title="Exit">
<item
android:id="#+id/credits"
android:title="Credits"
/>
<menu
xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/stay"
android:title="Cancel"
/>
<item
android:id="#+id/exit"
android:title="Exit" />
</menu>
</item>
<item
android:id="#+id/new_game"
android:title="Start the Game"
/>
</menu>
I set up the credits as just a normal "Hello World" Activity in the Java file for it Here is the Android Manifest declaration for the activity. I'm including this just in the case that the error was in there by chance.
<activity android:name=".Credits"
android:label="Application Credits"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape" >
</activity>
If anybody could please tell me where I messed up and what I need to do tof ix it.
Here is the Credits.java asked by Sam below
package com.apw.games.rpg.medieval;
import android.app.*;
import android.os.*;
import android.view.*;
public class Credits extends Activity
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.credits);
}
}
Your menu layout is incorrect. The problem is "Credits", you cannot have nested items: <item><item></item></item>. Either move "Credits" into the submenu or move it into the regular menu:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/visit_site"
android:title="Visit the Medieval Site!"/>
<item
android:id="#+id/quit"
android:title="Exit">
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/stay"
android:title="Cancel"/>
<!-- I moved credits here -->
<item
android:id="#+id/credits"
android:title="Credits"/>
<item
android:id="#+id/exit"
android:title="Exit"/>
</menu>
</item>
<item
android:id="#+id/new_game"
android:title="Start the Game"/>
<!-- Or you can move credits here -->
</menu>
Notice the layers are <menu> <item> <menu> <item> </item> </menu> </item> </menu>.