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.
Related
I want to make 3 similar buttons, the difference between them is that they are different colors. I had found out earlier that the way to give the buttons rounded corners is through creating an xml file for it, but in that case I had added the color for the button into the xml file. In this case I don't want to do that, since then I would have to make 3 virtually identical xml files to change the color for each button. Is there a way to split the code to have all three buttons reference a single xml for the button style, and have a separate line of code to just modify the color?
Within the values folder of your project, create a styles.xml file (if it doesn't already exist). Then, add code similar to below to set the common features that you want each button to have:
<!-- Style for a button -->
<style name="buttonStyle">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:fontFamily">sans-serif</item>
<item name="android:textAllCaps">false</item>
</style>
Then, in your layout file, reference this style that you just created in all three of your buttons similar to the following:
<Button
android:id="#+id/restore_button"
style="#style/buttonStyle"
android:layout_width="200dp"
android:textSize="18sp"
android:layout_height="wrap_content"
android:text="#string/restore_button_text" />
Then, change the color of each button individually with the following code in each button layout:
android:background="#android:color/white"
Finally, if you want to also create a button with rounded corners, reference this StackOverflow post for directions:
How to make the corners of a button round?
You will need to create a custom layout and reference it within each button as a Drawable.
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"
Does anyone know how can I change this green color that appears in my editText ?
I would like to do it from the layout XML if it is possible
just below the editText image.
Any help is appreciated.
I could resolve it adding: android:backgroundTint="#color/color_you_wat" to the EditText in the layout file
Programmatically:
editText.getBackground().mutate().setColorFilter(getResources().getColor(R.color.your_color), PorterDuff.Mode.SRC_ATOP);
Using theme:
<style name="AppThem" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- change values below to make same eefect for all EditTexts ->
<item name="colorControlNormal">#c5c5c5</item>
<item name="colorControlActivated">#color/accent</item>
<item name="colorControlHighlight">#color/accent</item>
</style>
<!-- also you can create different styles with values above for many different views ->
Edit:
You can always use in xml file:
"app:backgroundTint="#color/myColor" in xml.
Don't use android:. Otherwise you would lose backward compability with Android 4.4 and older.
Hope it help
I had developed an Android app that works fine on smartphones. When trying on Amazon Fire TV, I see that no view has focus on launch and the key presses on the remote controller don't have any effect. How can I make an item on the action bar have focus (the action item should have focus, namely blue lines around it). Since no view seems to have focus, the remote controller does not work.
Do I have to add something to the layout code, which is as follows:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_item_favorites"
android:icon="#drawable/ic_action_favorites"
android:title="#string/favorites"
android:showAsAction="always" />
...
...
...
</menu>
or do I have to set focus programmatically in onCreate or onStart?
Is it possible to change textColor in ListView without defining custom adapter for it? As in TextView we can apply style = "#style/mystyle" in which we can define textcolor.
<ListView
android:id="#+id/listview"
style="#style/WhiteText"
/>
In values, the style is defined as:
<resources>
<style name= "WhiteText">
<item name ="android:textColor">#FFFFFF </item>
<item name="android:background">#000000 </item>
</resources>
I tried it but it's not giving me desired output. So I want to ask, is it a valid way or not?
might be possible with to define the style for the ListView and set the Text color for that.
See below SO Answer:
First
Second
Hope it will help you.
If any query then let me know.