android: Custom Submenus - java

I want to create a customized submenu where i can add an "about page" to my application. So my submenu would just be a text view with a bunch of info. Im currently defining my menu in XML. Any help or links would be great, thanks!!!
<?xml version="1.0" encoding="UTF-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/settings_menu"
android:title="Settings" />
<item android:id="#+id/about_menu"
android:title="About">
<menu>
<item android:id="#+id/about_submenu"
android:title="Tip Message" />
</menu>
</item>
<item android:id="#+id/quit_menu"
android:title="Quit" />
</menu>
Also just out of curiosity, how would i define a more complex custom submenu, like one that takes user input from a keyboard.

I think it's easier to make something look like a menu. Try Activity with #android:drawable/menu_submenu_background as a background for example.

Related

tools:showIn="navigation_view" not working

When i append tools:showIn="navigation_view" to my code it's not showing. But in video which i watched from Youtube this is working fine. What is the problem? Also I can't add library called
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_home"
android:icon="#drawable/ic_main_home"
android:title="#string/home" />
<item
android:id="#+id/nav_timetable"
android:icon="#drawable/ic_subject_timetable"
android:title="#string/timetable" />
<item
android:id="#+id/nav_ogrnot"
android:icon="#drawable/ic_ogrnot"
android:title="#string/ogrnot" />
<item
android:id="#+id/nav_yemek_menu"
android:icon="#drawable/ic_yemek_menu"
android:title="#string/yemek_menu" />
<item
android:id="#+id/nav_homework"
android:icon="#drawable/ic_homework"
android:title="#string/homework" />
</group>
<item android:title="#string/optional">
<menu>
<item
android:id="#+id/nav_to_do_list"
android:icon="#drawable/ic_to_do_list"
android:title="#string/to_do_list" />
<item
android:id="#+id/nav_logout"
android:icon="#drawable/ic_logout"
android:title="#string/logout" />
</menu>
</item>
</menu>
I had the same issue with my code. The first thing I did was to delete my already created menu file (Android resource file) and start the process from the top.
Secondly, after creating the menu resource file, on a new line, after typing (tool:), press alt+enter to add this automatically for you... xmlns:tools="http://schemas.android.com/tools"... Then you can go ahead to type in tools:showIn=".....".
To know if this works, in line of code in tools:showIn, when typing the name in the quotes, just type "na'... if there are other popups or suggestions, then you're good to go.
Hope this helps.

Is this possible to call ' Okay Glass' only once

Is this possible to call ' Okay Glass' only once rather than speaking ok glass every time before giving any voice command?
For example, I start my application and call 'Okay glass' once and start giving voice commands and switching to different activities by voice commands without repeating 'Okay glass' before each voice command.
If you have a list of items where each item has a sublist, you could use a menu:
res/menu/store.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/store"
android:title="Buy an item">
<menu>
<item
android:id="#+id/produce"
android:title="Produce">
<menu>
<item
android:id="#+id/apples"
android:title="Apples"/>
<item
android:id="#+id/bananas"
android:title="Bananas"/>
<item
android:id="#+id/lettuce"
android:title="Lettuce"/>
<item
android:id="#+id/guava"
android:title="Guava"/>
</menu>
</item>
<item
android:id="#+id/meat"
android:title="Meat">
<menu>
<item
android:id="#+id/pork"
android:title="Pork"/>
<item
android:id="#+id/beef"
android:title="Beef"/>
<item
android:id="#+id/chicken"
android:title="Chicken"/>
</menu>
</item>
</menu>
</item>
</menu>
I say "Ok Glass, buy an item" and it lists a menu with "Produce" and "Meat." Then I say "Produce" (without having to say "Ok Glass") and it lists the produce in the menu. When I say "Bananas," it opens the activity for buying bananas (see this project for details on that: https://github.com/alk2pb/GlassFoley/blob/master/app/src/main/java/com/example/team8capstone/glassfoley/video/VideoActivity.java).
This answer might be relevant, too: How can I dynamically create menu items?

Android - How to add a default checked CheckBox to Navigation Drawer

I want to add a check box to Navigation Drawer, and I want one of them to be default checked
I'm using this: app:actionViewClass="android.widget.Switch" as suggested in this answer.
But I couldn't figure out how to make one of them default checked. If I use this property android:checked="true", then the option is checked instead of checkbox (See image).
Does anyone know how to make it default checked (if possible, I want to do it in XML only)?
Here is my activity_drawer.xml.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:showIn="navigation_view">
<group
android:checkableBehavior="single">
<item
android:id="#+id/checkboxX-axis"
android:title="Show x-axis"
android:icon="#drawable/ic_x_axis_black_24dp"
app:actionViewClass="android.widget.CheckBox"
android:checked="true"
/>
<item
android:id="#+id/checkboxY-axis"
android:title="Show y-axis"
android:icon="#drawable/ic_y_axis_black_24dp"
app:actionViewClass="android.widget.CheckBox"
/>
<item
android:id="#+id/checkboxZ-axis"
android:title="Show z-axis"
android:icon="#drawable/ic_z_axis_black_24dp"
app:actionViewClass="android.widget.CheckBox"
/>
</group>
</menu>
You can do this:
MenuItem item = navigation.getMenu().findItem(R.id.checkboxX-axis);
CompoundButton compoundButton = (CompoundButton) item.getActionView();
compoundButton.setChecked(true);
replace navigation with the NavigationView's name.

How to expand android ActionBar?

How can i expand the actionbar like PlayNewsstand application and the image below :
What i am looking for found it here.
For your concern try using this in your manifest file ..
yourapp:showAsAction="ifRoom"
Ex:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
yourapp:showAsAction="ifRoom" />
...
</menu>
Complete reference :: http://developer.android.com/guide/topics/ui/actionbar.html

Android, How to change the actionbars logo button on state change?

So I'm wondering how one could implement to an action bar with a logo button, a different image per state.(pressed, released etc).
I know how to do this for a normal button, but I'm not sure if it's possible with the actionbars logo button?
And if it's not, how could one implement am action bar that supports this? externals libs?
Thank you.
Create a drawable xml file in res/drawable such as res/drawable/button_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/button_pressed"
android:state_pressed="true" />
<item android:drawable="#drawable/button_normal" />
</selector>
where button_pressed and button_normalare just regular png files in one of your drawable directories (e.g/ drawables-hdpi)
Then in your menu.xml or in your code you can refer to #drawable/button_selector or R.drawable.button_selector and the image will change automatically when the button is pressed.
If you need to change the ActionBar button background you need to override the theme in your res/values/style.xml.
<style name="YourTheme.Sherlock" parent="#style/Theme.Sherlock">
<item name="actionBarItemBackground">#drawable/actionbar_item_background_selector</item>
<item name="android:actionBarItemBackground">#drawable/actionbar_item_background_selector</item>
</style>
Both lines matter: one for the SherlockActionBar and one for the standard ActionBar
Then set the theme to your activity in the manifest:
<activity
android:name=".yourActivity"
android:theme="#style/YourTheme.Sherlock" >
</activity>
And here is actionbar_item_background_selector.xml to be placed in res/drawable
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
<item android:state_focused="true" android:state_enabled="false" android:state_pressed="true" android:drawable="#drawable/scene_overlay_bar_pressed_center" />
<item android:state_focused="true" android:state_enabled="false" android:drawable="#drawable/abs__list_selector_disabled_holo_light" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="#drawable/scene_overlay_bar_pressed_center" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="#drawable/scene_overlay_bar_pressed_center" />
<item android:state_focused="true" android:drawable="#drawable/abs__list_focused_holo" />
<item android:drawable="#android:color/transparent" />
</selector>
replace the background with the drawable of your choice where android:state_pressed="true"
It's a lot to do for just a background but that is how the ActionBar works.
you can use a selector to pick different image.
Android ImageButton with disabled UI feel
may be help
I think you are looking for this:
final ActionBar bar = getActionBar();
bar.setDisplayHomeAsUpEnabled(true);
This automatically makes the logo you have set look like its being pressed when its clicked. No need to have different images to show state change. Thats a pretty easy way. Though if you are using ActionBarSherlock this won't work, I think. Strictly 4.0 I believe. Check out the doc on ActionBar.

Categories