Icon of the menu item not appearing - android-studio

I hope to find answer of this question and any help will be appreciated,
when i use blank\empty activity the icon of the menu item doesn't appear !
but using basic activity it works fine .
thanks in advance .
this is the menu xmlcode
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/one"
android:icon="#drawable/images"
android:showAsAction="always"
android:title="one"
/>
its works as i said for basic Activity but its not for empty\blank Activity
for the appearance of the menu icon

xmlns:app="http://schemas.android.com/apk/res-auto" put this in menu before your item tag and use 'app:' instead of 'android:' at "showAsAction" LIKE
use this:
app:showAsAction="always"
instead of
android:showAsAction="always"

Related

Android app preferences page doesn't show toolbar

I'm trying to add a preferences page to my Android app.
I've added an <item> to my <menu> that gets "inflated" in onCreateOptionsMenu to make it appear in the <androidx.appcompat.widget.Toolbar> in main_activity.xml.
(1) it shows up as the cog icon that I added, not as the three dots -- why? How do you get the three dots?
When I go to the settings page my toolbar disappears, but in all the examples the toolbar shows the title and a back button.
I have edited the manifest.xml to add the android:parentActivityName=".MainActivity" stuff.
(2) why does my toolbar disappear?
I've defined a list of values another list of labels to use in a <ListPreference> but it doesn't work.
<ListPreference
android:dialogTitle="Select units"
android:entries="#array/units_names"
android:entryValues="#array/units_values"
android:key="list"
android:summary="Click to show a list to choose from"
android:title="Units" />
<resources>
<string-array name="units_values">
<item>miles</item>
<item>km</item>
</string-array>
<string-array name="units_names">
<item>miles</item>
<item>km</item>
</string-array>
</resources>
3 Why isn't this working?! I really can't see what I've got wrong.
So it turns out that the <item> in the <menu> have their icons shown in the toolbar, but if there isn't enough room then the three dots appear automatically and the overflowed items go in there.
This can be controlled to some extent with the attribute app:showAsAction on the <menu> items.
The problem with items not appearing is that that the text is black.
It can be changed in styles.xml with:
<item name="android:textColorAlertDialogListItem">#color/text</item>
and some others, although it appears not to be document what the names of those other colours are -- typical.

Android Studio Material design menu inflation

I am trying to inflate a menu when selecting items from the list for multiple deletion, but instead I get a new menu bar on top of the current one.
http://imgur.com/XRAEnBM.jpg
I used the default navigation drawer activity and then made my fragments.
I am using listView.setMultiChoiceModeListener this is my code
Java Code:
#Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mode.getMenuInflater().inflate(R.menu.delete, menu);
return true;
}
XML Code in menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/delete_id"
android:title="Delete"
android:icon="#drawable/ic_action_delete"/>
</menu>
The Java code happens in on onResume() in one of my fragments.
I am a beginner so please be kind thanks :)
Here is the solution, just add these two lines in your stlyes
<item name="windowActionModeOverlay">true</item>
<item name="actionModeBackground">#color/colorPrimary</item>

android menu icon do not display

i am using appcompat for my actionbar for 2.3。
i want collapseActionView when i click the options but not display at first。
![enter image description here][1]
As the img shows ,the menus do not show icons.
Could somebody help me .tks very much.
here are my codes.
<?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"
xmlns:tools="http://schemas.android.com/tools" >
<item
android:id="#+id/zhuangtai"
android:icon="#drawable/fa"
android:showAsAction="collapseActionView"
android:title="发状态"
app:showAsAction="collapseActionView"/>
<item
android:id="#+id/er"
android:icon="#drawable/sao"
android:showAsAction="collapseActionView|withText"
android:title="扫一扫"
app:showAsAction="collapseActionView|withText"/>
<item
android:id="#+id/sui"
android:icon="#drawable/sui"
android:showAsAction="collapseActionView|withText"
android:title="随份子"
app:showAsAction="collapseActionView|withText"/>
<item
android:id="#+id/haoyou"
android:icon="#drawable/haoyou"
android:showAsAction="collapseActionView|withText"
android:title="好友列表"
app:showAsAction="collapseActionView|withText"/>
</menu>
sorry for my english.
The android:showAsAction introduced in API Level 11. In this case you are using Api level 9. Read this tutorial. Its helps you.
collapseActionView The action view associated with this action item (as declared by android:actionLayout or android:actionViewClass) is collapsible.
Introduced in API Level 14.
So, one simple way is to remove collapseActionView

Layout like Cards in android

I want to make an android layout like Google Cards,i know there is an Open Source Libraries, however i want only the Layout and the gray hex background style. I could not find information about this, how i can make this possible? im Attaching new Google maps v7 Layout so you can get the idea.
bg_card.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#CCC" />
</shape>
</item>
<item android:bottom="2dp">
<shape android:shape="rectangle">
<solid android:color="#FFF" />
</shape>
</item>
</layer-list>
Or just set the background of the card to #FFF and add at the bottom:
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#CCC" />
NOTE:
For everyone who doesn't care about using a library, you should use
a CardView from the Android support library.
Sample code.
<item name="android:windowBackground">#ffe3e3e3</item>
In your style.xml should make you happy ;-)
And for the layout, copying the card background should be enough isn't it?
We can use the LayerList as above to achieve this (OR) by using the nine patch image get same effect, we need not create nine patch image separately for this puprpose android drawable have one.
if you are using eclipse: android:background="#drawable/abc_menu_dropdown_panel_holo_light"
copy paste the above line as your View backround.
or if you are using android studio copy paste the following line:
android:background="#android:drawable/dialog_holo_light_frame"

Android Border Less Button Pressed State Background Color

How can we change the background colour of a Border less button when the button is pressed.
I used this:
android:background="?android:attr/selectableItemBackground"
android:text="#string/btn_skip"
Where my button Displays a label "SKIP" as defined in my "strings.xml".
Now When I test this it is Good Except It shows default "Blue" Colour when in Pressed State.
I want it to match it with other elements of my My UI theme that are "Orange" "#FF8800"
Any Ideas?
Thankx in advance...!
instead of using ?android:attr/selectableItemBackground you can create a xml in drawable in folder with following content.
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true">
<item
android:state_pressed="true"
android:drawable="#color/orange"/>
<item
android:state_enabled="false"
android:drawable="#color/default"/>
<item
android:drawable="#color/default"/>
</selector>
Updated:
so you save this files as : btn_drawable.xml in drawable folder.
Simply replace ?android:attr/selectableItemBackground
with *#drawable/btn_drawable.xml*
Thanks #Nimish-Choudhary ...! I followed your advice. and I have explained it further for clarity to all having same question as me as a beginner.
Create an xml with name say "btntransparent.xml"
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true">
<item
android:state_pressed="true"
android:drawable="#color/pressed"/>
<item
android:state_enabled="false"
android:drawable="#color/defaultColor"/>
<item
android:drawable="#color/defaultColor"/>
</selector>
Next add the colors "pressed" and "defaultColor" to another xml say "colors.xml"
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="pressed">#CCFF8800</color>
<color name="defaultColor">#00000000</color>
</resources>
Here "#CCFF8800" is my pressed state Translucent Orange and "#00000000" is the 100% Transparent Black (;-) thats invisible). You can find more about color codes at Color| Android Developers
Now put the "colors.xml" in values Folder and "btntransparent.xml" in drawable Folder.
Now the last step is to voila use it in the button as
<Button
android:id="#+id/id_btn_skip"
android:background="#drawable/transparentbtn"
android:onClick="skipToMain"
android:text="#string/btn_skip" />
And thats should do the job...!
Take care.
regards,
raisedadead
If I understand you correctly, what you could do is add new resource in #drawable for example my_ripple.xml
<?xml version="0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#FF8800">
</ripple>
Then simply set this as your background.
In your theme add the following:
<item name="android:selectableItemBackground">#FF8800</item>
to override the default blue.

Resources