How can I change background colour of search support fragment in android leanback library. I have tried to find a public function to do the same just like in BrowseSupportFragment.
Try this:
val backgroundManager = BackgroundManager.getInstance(requireActivity())
val backgroundManager.attach(requireActivity().window)
backgroundManager?.color = Color.parseColor("#ff0000")
It works for the RowsSupportFragment, so I guess it works for search too
Related
I'm using the Google maps utility library to generate an icon for my markers, and the setColor is not working, every color I set, is a different shade of blue, it's not my color, and it's also got a black stroke around, which I don't want.
this is the code:
for (place in location.locations) {
val locationPoz = LatLng(place.lat, place.long)
boundsBuilder.include(locationPoz)
//Here is the icon part
val icon = IconGenerator(requireContext())
icon.setColor(R.color.red)
val fIcon = icon.makeIcon("${place.price}€")
val marker = MarkerOptions()
.position(locationPoz)
.title(place.name)
.icon(BitmapDescriptorFactory.fromBitmap(fIcon))
.alpha(5f)
googleMap.addMarker(marker)
}
And this is how my map looks
I think you can only use one of the provided values in https://googlemaps.github.io/android-maps-utils/javadoc/com/google/maps/android/ui/IconGenerator.html
Try
~icon.setColor(IconGenerator.STYLE_RED)~
EDIT: I misread, I think. The STYLE_* values would have to be used like
icon.setStyle(IconGenerator.STYLE_RED)
That doesn't yet solve your problem of the border you don't want, so instead, you would need to provide your own background drawable with setBackground
I want to do something new in my app. I want to create Progress Bar without using tag of xml in android .is there any way to do that ? if yes then please share with me? The purpose of doing this is that i don't want to declare Progress Bar for each of my layout file. I completely want to make it using Kotlin Code in android. thanks in advnance
You can use the ProgressIndicator provided by the Material Components Library.
For example a CircularProgressIndicator:
val layout = findViewById<LinearLayout>(R.id.layout)
val indicator = CircularProgressIndicator(this)
indicator.isIndeterminate = true
indicator.trackColor = ContextCompat.getColor(this,R.color.xxx)
indicator.indicatorSize = resources.getDimensionPixelSize(R.dimen.indicator100dp)
indicator.setIndicatorColor(ContextCompat.getColor(this,R.color.xxx))
indicator.show()
layout.addView(indicator)
Or a LinearProgressIndicator
val indicator = LinearProgressIndicator(this)
indicator.isIndeterminate = true
indicator.trackColor = ContextCompat.getColor(this,R.color.xxxx)
indicator.trackThickness = resources.getDimensionPixelSize(R.dimen.cornerSize8)
indicator.setIndicatorColor(ContextCompat.getColor(this,R.color.xxx))
indicator.show()
layout.addView(indicator)
I'm using highcharts for android. I wanna change exporting button background. How can I do that?
In order to set the background color of your exporting button, you can use navigation.buttonOptions.theme.fill property. Here is how to implement it using our Android wrapper:
HINavigation navigation = new HINavigation();
navigation.buttonOptions = new HIButtonOptions();
navigation.buttonOptions.theme = new HITheme();
Navigation.buttonOptions.theme.fill = „#ff0000”;
API Reference: https://api.highcharts.com/android/highcharts/
I have a Xamarin.Forms SearchBar on a StackLayout with a dark background color.
By default the input field is dark as well, probably due to a transparent background. To modify the search bar background color there is a BackgroundColor property. (In the example below I set it to dark gray.)
But how to adjust the text color? There is no such property. And even with a custom search bar renderer I don't find a solution.
This is how it looks with just the placeholder:
...and with some input (black "Hello world!" on a pretty dark background):
Here is the code for an Android Custom renderer that will do the trick. I would upload a screenshot, but I don't have enough points yet :(
using System;
using Android.Widget;
using Android.Text;
using G = Android.Graphics;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly:ExportRenderer( typeof(MySearchBar), typeof(Some.Namespance.MySearchBar_Droid) )]
namespace Some.Namespace
{
public class MySearchBar_Droid : SearchBarRenderer
{
protected override void OnElementChanged( ElementChangedEventArgs<SearchBar> args )
{
base.OnElementChanged( args );
// Get native control (background set in shared code, but can use SetBackgroundColor here)
SearchView searchView = (base.Control as SearchView);
searchView.SetInputType( InputTypes.ClassText | InputTypes.TextVariationNormal );
// Access search textview within control
int textViewId = searchView.Context.Resources.GetIdentifier( "android:id/search_src_text", null, null );
EditText textView = (searchView.FindViewById( textViewId ) as EditText);
// Set custom colors
textView.SetBackgroundColor( G.Color.Rgb( 225, 225, 225 ) );
textView.SetTextColor( G.Color.Rgb( 32, 32, 32 ) );
textView.SetHintTextColor( G.Color.Rgb( 128, 128, 128 ) );
// Customize frame color
int frameId = searchView.Context.Resources.GetIdentifier( "android:id/search_plate", null, null );
Android.Views.View frameView = (searchView.FindViewById( frameId ) as Android.Views.View);
frameView.SetBackgroundColor( G.Color.Rgb( 96, 96, 96 ) );
}
}
}
You can achieve this by creating a custom View that has a bindable-property like ForegroundTextColor and then create a custom renderer.
In the custom renderer you can inherit from the platform specific renderer, i.e. on WindowsPhone it is:-
Xamarin.Forms.Platform.WinPhone.SearchBarRenderer
You can then monitor for property changes to the bindable-property you created and set the platform native control Text-color that is used to change the appearance of the non-editing view of the SearchBar.
You also have to monitor for IsFocused and apply the colouring on WindowsPhone, at least, also. This may also apply for other platforms possibly as well.
Update 1:-
========
In reply to your comment you don't have to render the whole SearchBar yourself.
If you inherit from the renderer you are able to customize things finer.
With specific reference to Android to achieve this you have to get reference to AutoCompleteTextView and then you can call SetTextColor to change the color.
Update 2:-
==========
SearchBar is a composite control in Android.
The AutoCompleteTextView is buried rather deep in the hierarchy.
On 4.4 this can be found using the following code. Other versions may well differ. This is by no means a good approach necessarily for production using ordinal indexes however:-
AutoCompleteTextView objAutoTextView = (AutoCompleteTextView)(((this.Control.GetChildAt(0) as ViewGroup).GetChildAt(2) as ViewGroup).GetChildAt(1) as ViewGroup).GetChildAt(0);
Where this is the renderer class.
You can then call objAutoTextView.SetTextColor with the color to achieve the change in color to the SearchBar foreground text.
I finally found a very simple solution:
I accidentally used the Android Theme #android:style/Theme.Holo.Light and modified all colors explicitly. But to get a bright text color on a search bar you better use #android:style/Theme.Holo.
It does not allow you to set the color very precisely, but changing it from black to white was all I needed in this case.
You can make the following changes in the xaml if you are using xaml to obtain the different text color of search bar on different platforms:
<SearchBar x:Name="Search"
Placeholder="Search"
TextChanged="SearchBar_OnTextChanged"
SearchButtonPressed="OnSearch" BackgroundColor="#19588F">
<SearchBar.TextColor>
<OnPlatform x:TypeArguments="Color">
<OnPlatform.iOS>
Black
</OnPlatform.iOS>
<OnPlatform.Android>
White
</OnPlatform.Android>
<OnPlatform.WinPhone>
White
</OnPlatform.WinPhone>
</OnPlatform>
</SearchBar.TextColor>
</SearchBar>
Here's how I did it, another way:
[assembly: ExportRenderer(typeof (CustomSearchBar), typeof (CustomSearchBarRenderer))]
namespace Bahai.Android.Renderers
{
public class CustomSearchBarRenderer : SearchBarRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
{
base.OnElementChanged(e);
if (e.OldElement == null)
{
SearchBar element = (SearchBar) this.Element;
var native = (global::Android.Widget.SearchView) Control;
// do whatever you want to the controls here!
//--------------------------------------------
// element.BackgroundColor = Color.Transparent;
// native.SetBackgroundColor(element.BackgroundColor.ToAndroid());
// native.SetBackgroundColor(Color.White.ToAndroid());
//The text color of the SearchBar / SearchView
AutoCompleteTextView textField = (AutoCompleteTextView)
(((Control.GetChildAt(0) as ViewGroup)
.GetChildAt(2) as ViewGroup)
.GetChildAt(1) as ViewGroup)
.GetChildAt(0);
if (textField != null)
textField.SetTextColor(Color.White.ToAndroid());
}
}
}
}
SearchBar has a TextColor property. At least in Xamarin 5.
<SearchBar
TextColor="Black"
Text="{Binding SearchString}">
I wanted to try out this funny title bar coloring, but it doesn't work for me as
getWindow().findViewById(android.R.id.title);
returns null. So I had a look at it with Hierarchy Viewer and found out that the view is called id/action_bar instead. But there's no R.id.action_bar (autocomplete doesn't offer it and there's nothing like this is R.java).
So now I'm doubly confused:
Is android.R.id.title sort of obsolete now (I'm using version 16 in my emulator)?
Where does id/action_bar come from?
What's the recommended and simple practice w.r.t. compatibility?
Should I get ActionBarSherlock? I originally just wanted to change the title bar color... not fool around with it a lot.
Use the code below to get the ActionBar's id:
val actionBarId = resources.getIdentifier("action_bar", "id", packageName)
And use findViewById you can find the action bar.
Then find the title from actionbar's children (in normal cases):
val actionbar = findViewById<ViewGroup>(actionBarId)
for (view in actionbar.children) {
if (view is TextView) {
// this is the titleView
}
}
However, if you just want to change the title view's text, just use getSupportActionBar:
supportActionBar?.apply {
// set title text
title = "Hello"
// set colored title text
val coloredTitle = SpannableString("Hello")
coloredTitle.setSpan(ForegroundColorSpan(Color.RED), 0, coloredTitle.length, 0)
title = coloredTitle
}
I would recommend using ActionBarSherlock if you're looking for compatibility with Android versions before API level 14 / Android 4.0.
Changing the background of the ActionBar is straightforward and is most easily done via styles. See the "Background" section of http://android-developers.blogspot.com/2011/04/customizing-action-bar.html
You can also change it via code. Put this in your onCreate():
GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] {Color.RED, Color.GREEN});
getActionBar().setBackgroundDrawable(gradientDrawable);
Here is a screenshot of this code in action: