Set font custom searchview Android studio - android-studio

Select the custom font for search view:
searchView = (SimpleSearchView) findViewById(R.id.searchView);
searchView.getSearchEditText().setTypeface(AppFontClass.getCurrentTypeFace(getApplicationContext()));

TextView searchText = (TextView) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
Typeface myCustomFont = Typeface.createFromAsset(getAssets(),"fonts/myFont.ttf");
searchText.setTypeface(myCustomFont);

Related

How to set font weight programmatically?

I want to change the font weight in TextView but i can't find the required method.
How can i do it without creating a new font?
You can only show a TextView as Light, Regular and Condensed if the font that you're referencing allows those styles.
private TextView AB;
Typeface someFontName-condensed = Typeface.createFromAsset(getAssets(), "assets/NameOfFont-condensed.ttf");
AB = (TextView) findViewById(R.id.myTextViewId);
AB.setTypeface(someFontName-condensed);
I have found the right answer. There is the static method:
open static fun create(family: Typeface?, weight: Int, italic: Boolean): Typeface
For example, if you want the font weight to be 700:
var text = findViewById<TextView>(R.id.text)
text.typeface=Typeface.create(null,700,false)

How to change the color from Picker in Xamarin Mac?

I have a picker on my Xamarin mac app, I want to change the background color and the border color (blue), How can I do that?
Picker picker1 = new Picker { Items = { translateExt.transltR("Option1"), "Option2", "Option3" }, SelectedIndex = outputMode, WidthRequest = 210, TextColor = Color.FromHex(fileManagerPlatform.getColorText()), VerticalOptions = LayoutOptions.CenterAndExpand};
picker1.BackgroundColor = Color.Transparent;
The previous code works on Android, iOs, UWP to change the background color, but not on Mac.

Android Spannable dismiss after editing

I am implementing mentions as in twitter #username. But mentions can't be typed, only selected from MultiAutoCompleteTextView.
I am creating spannable with blue text color on treminateToken
Spannable sp = new SpannableString(text + " ");
sp.setSpan(new ForegroundColorSpan(Color.BLUE), 0, text.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
But the problem is that user can edit this text.
How to make this snap non editable? To delete whole span when user press backspace?
Or at least change color back to black if it have been edited.
Try this
Pass your string to this below method using key listener of your editext
public void displayText(String s)
{
String ss[]=s.split(",");
for(int i=0;i<ss.length;i++)
{
final SpannableStringBuilder sb = new SpannableStringBuilder();
TextView tv = createContactTextView(ss[i]);
BitmapDrawable bd = (BitmapDrawable) GlobalMethods.convertViewToDrawable(tv);
bd.setBounds(0, 0, bd.getIntrinsicWidth(),bd.getIntrinsicHeight());
sb.append(ss[i] + ",");
sb.setSpan(new ImageSpan(bd), sb.length()-(ss[i].length()+1), sb.length()-1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
contact.setText(sb);//your edit text here
}
}
set text style
public TextView createContactTextView(String text)
{
TextView tv = new TextView(this);
tv.setText(text);
tv.setTextSize(25);
tv.setBackgroundResource(R.drawable.design);
return tv;
}
Output:
if the user try to delete the text it delete the whole text

Align textView next to another one programatically

I am programmatically creating a text view and trying to place another textView right next to the first one. But I am unable to do it.
Here is the code I have written,
//1st textview
TextView itemText = new TextView(context);
itemText.setText(mItemText);
Typeface itemFont = Typeface.createFromAsset(context.getAssets(), "fonts/" + "Roboto" + ".ttf");
itemText.setTypeface(itemFont,Typeface.BOLD);
itemText.setPadding(0, padding, 0, 0);
itemText.setId(10);
RelativeLayout.LayoutParams itemTextParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT);
itemTextParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
itemTextParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
itemText.setTextSize(font_size);
itemText.setLayoutParams(itemTextParams);
//2nd text view
TextView seperator = new TextView(context);
seperator.setText(mSeperator);
seperator.setPadding(0,padding,0,0);
seperator.setTypeface(null,Typeface.BOLD);
RelativeLayout.LayoutParams seperatorParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
seperatorParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
seperatorParams.addRule(RelativeLayout.RIGHT_OF,itemText.getId());
seperatorParams.addRule(RelativeLayout.CENTER_VERTICAL);
seperator.setLayoutParams(seperatorParams);
seperatorParams.addRule(RelativeLayout.CENTER_HORIZONTAL) works, but when I use seperatorParams.addRule(RelativeLayout.RIGHT_OF,itemText.getId()) , the text is not shown.
Can anyone point out where I am going wrong? Or is there any other way to do this?
The width of itemTextParams is set to MATCH_PARENT, so there's no space to put anything to the right of it. Change it to WRAP_CONTENT or define a width value.

Add text view to dialog

I'm trying to align right text in my dialog.
How can I do that ?
I've tried to:
TextView loadMsg = new TextView(context);
loadMsg.setText("טוען...");
loadMsg.setGravity(Gravity.RIGHT);
dialog.setView(loadMsg);
dialog.show();
But the text does not show.
Sub-way: Create a sub layout and set content view by this
dialog.setContentView(R.layout.dialog_layout);
And design the sub layout the way you like :D
This is because you set the gravity inside the TextView. But if your TextView is laid out with WRAP_CONTENT the gravity really doesn't matter for such a short String. You should insert the TextView inside some Layout, specify FILL_PARENT and setting the layout as the Dialog content view
// width is FILL_PARENT -1, height is WRAP_CONTENT -2
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(-1, -2);
LinerLayout layout = new LinearLayout(context, params);
layout.addView(loadMsg, params);
dialog.setView(layout);
Alternatively, you can set the gravity on the layout itself and set the TextView's width to WRAP_CONTENT
Maybe you are missing LayoutParams in which you have to define heigh and width. If you use wrap_content for width then it would not be aligned as there will no be any extra space.

Resources