Android - Customizing the Spinner widget Look and Feel - android-widget

Is it possible to change the color of the radio button in the Android spinner widget. By default it displays the green color for the radio button.
I need to change it to some other color, is it possible, and how?

I know this is an old question now, but here goes...
You will need to create a custom Theme and apply it to the Activity with your spinner.
First, you need to create images for the checked/unchecked states of the 'new' radio, you could just pull the given images btn_radio_on.png and btn_radio_off.png from the sdk's res/drawable-* folder(s). Edit them to look how you want (such as changing color or whatever) and save off to your project.
Next, create a new xml file in your res/values folder, and add the following:
<resources>
<style name="CustomSpinnerRadioTheme" parent="#android:style/Theme">
<item name="android:spinnerDropDownItemStyle">#style/EditedRadio</item>
</style>
<style name="EditedRadio" parent="#android:style/Widget.DropDownItem.Spinner">
<item name="android:checkMark">#drawable/edited_radio</item>
</style>
</resources>
Then, create another xml file in res/drawable named edited_radio.xml, and it should contain the following:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false" android:drawable="#drawable/btn_radio_off" />
<item android:state_checked="true" android:drawable="#drawable/btn_radio_on" />
</selector>
just be sure to reference your edited images for the checked states. Then you just have to apply the CustomSpinnerRadioTheme to your Activity and run!
A good resource I found is Applying Styles and Themes especially the additional reference on Android Styles (styles.xml) and Android Themes (themes.xml)

Related

How to change cursor color in html-editor-enhanced flutter

I am using html-editor-enhanced to compose.
I'm having problems synchronizing the cursor colors with the app's colors. when I focus on Editor, the default color of the cusor is green. while my app has a different color. How do I change the color of this cursor?
Hope to get help from the community.
I have found the answer to my question.
In android native. > Res>value> style.xml
add this line
<item name="android:colorControlActivated">#2F93EF</item>
Full code
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="#android:style/Theme.Light.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">#drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="#android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
<item name="android:colorControlActivated">#2F93EF</item>
</style>
</resources>

When I swipe from left to right, I don't want it to exit the wearos application in flutter

When I swipe from left to right, I don't want it to exit the wearos application (in flutter/wearos). What can I do for this?
actually, this path writes for kotlin and java in androiddevelopers but l can't see for flutter. so l wrote it for flutter. almost everything is same.
you should open styles.xml(android/app/src/main/res/values/styles.xml).Then you should write false this in Launch theme.
so it should looks like this
<style name="LaunchTheme" parent="#android:style/Theme.Light.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">#drawable/launch_background</item>
<item name="android:windowSwipeToDismiss">false</item>
</style>

Is it possible to add text in launch_background.xml (flutter)?

The question for me is, can I create a post in the launch_background.xml file to display when the page loads? I just managed to load the image and change the background color, I work with Flutter.
picture my source here
The only way to use a text is to give it also as a Bitmap
<item android:bottom="25dp">
<bitmap
android:gravity="center"
android:src="#drawable/myText" />
</item>
where myText is just some text converted to an image (using paint or whatever)

How to fix the App name on the top of the Activity

In my design page of My Android Studio Project, the App Name is shown in the top of the activity(Action Bar). But, when I debug the App, the App name is not Shown on the top of the Activity. I want the App name should be shown. How to fix it.
My styles.xml is...
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
Set your App theme to Theme.AppCompat.Light.DarkActionBar in style.xml
For e.g.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
I think you was asking about ActionBar
from docs
A primary toolbar within the activity that may display the activity
title, application-level navigation affordances, and other interactive
items.
Beginning with Android 3.0 (API level 11), the action bar appears at
the top of an activity's window when the activity uses the system's
Holo theme (or one of its descendant themes), which is the default.
You may otherwise add the action bar by calling
requestFeature(FEATURE_ACTION_BAR) or by declaring it in a custom
theme with the windowActionBar property.
If you want to change it from java code, write in
Activity.java
ActionBar ab = getActionBar();
ab.setTitle("My new title");
Or, in the Androidmanifest.xml file:
<activity
android:name=".MyActivity"
android:icon="#drawable/my_icon"
android:label="My new title" />
hope my answer help you..

How to get ListView selection color value?

I'm developing a custom control and would like to use same color ListView control uses to highlight selected item.
I tried to use context.getResources().getDrawable(android.R.drawable.list_selector_background)
and then use setBackgroundDrawable() on my view, but the background is still transparent.
I don't want to use states and I just need a color value or drawable I can use on my control as a background.
Please help!
I think the best option is to use a selector like that on your xml on your listview:
<ListView
....
android:listSelector="#drawable/selectable_background"
..../>
Then on you drawable folder you add an xml file like this :
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="#android:integer/config_mediumAnimTime" >
<item android:state_pressed="false" android:state_focused="true"
android:drawable="#drawable/list_focused" />
<item android:state_pressed="true"
android:drawable="#drawable/pressed_background" />
<item android:drawable="#android:color/transparent" />
</selector>
and again on your drawable folder you add this other xml file:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#color/green" />
</shape>
and on your drawable-hdpi you add this 9-patch file (change the color or the file or use this web to create your own one http://android-holo-colors.com/):
https://dl.dropboxusercontent.com/u/33565803/StackOverFlowExamples/list_focused.9.png
Like this you should be able to have your customise highlight color on your listview.
EDIT:
Background of the clickable view :
android:background="#drawable/pressed_button"
Selector for the default ListView highlight color (pressed_button.xml inside drawable folder):
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#android:drawable/list_selector_background"
android:state_pressed="true" />
<item android:drawable="#android:color/transparent"
android:state_focused="true" />
<item android:drawable="#android:color/transparent" />
</selector>
Well the list selector drawable is (usually) transparent in its default state. So you have to change the state first.
The pressed state could be used for example:
Drawable drawable = context.getResources().getDrawable(android.R.drawable.list_selector_background);
drawable.setState(new int[] {android.R.attr.state_pressed});
x.setBackgroundDrawable(drawable);
Where x is your view.
You can try like this,
For example you need the get the list item view by using below code
int visiblePosition = listview.getFirstVisiblePosition();
View view = listview.getChildAt(1 - visiblePosition);
// To get the color of particular listview item and set it,
View newView = listview.getChildAt(5 - visiblePosition);
newView.setBackgroundColor(((ColorDrawable) view.getBackground()).getColor());