Android - styling custom Dialog - android

I have a custom dialog in an xml layout.
How can I style it so it:
doesn't have a title
in other cases when I do want a title, change the color of the title divider line
has completely square edges instead of those slightly rounded corners that Android dialogs have by default

android customising style link
There is style folder inside res folder. Please take look over it. it basically xml file which has resource tags where you can configure you custom styling. And refer the same styling from style attribute in xml.

Related

How to Create a custom tab layout that mimics the default tab text

I need to create a custom tab layout, but I want the text to mimic the style used in the normal TabLayout.TabView.
To do that, I've set my text appearance to TextAppearance.Design.Tab.
If you take a look at TabLayout itself, you can see that's what TabView's text uses:
mTabTextAppearance = a.getResourceId(R.styleable.TabLayout_tabTextAppearance, R.style.TextAppearance_Design_Tab);
...
TextViewCompat.setTextAppearance(mTextView, mTabTextAppearance);
However, when my tabs display, I can clearly see the text is not the same. It's very similar, but the default tab looks to be more bold.
What am I doing incorrectly?
The answer was to set the text appearance programmatically. Setting android:textAppearance on the TextView in the XML file doesn't seem to do anything. Setting the text appearance programmatically (like TabLayout.TabView) works.

Custom button style with font style

Going to create android app, but as client requirement.
I have to come up with custom style buttons and radio button.
Review the attached image
How can I make the button and input field same as 'bullet point 1'.
How to use custom Arabic font style.
(i.e https://fonts.google.com/specimen/Cairo)
For bullet point 1, I would suggest you to use 9-patch images with stretchable area on top & bottom lines & keeping the circular arc on left/right edges of same radius.
I can try to create same 9-patch image for you, but it's gonna take time :) (give me the color codes you want to use in)
For using Arabic fonts, please go through this Android Developer link Android Custom Fonts.
There are plenty of answers out there on how to use custom fonts, so you can easily find any one.
Here's how you can easily use that Cairo fonts types:
Download the Cairo font zip file, unzip it & put all .ttf or .otf files inside your Project -> app -> src -> main -> res -> font folder
Add below lines into your styles.xml file under res->values folder:
<style name="cairo_semi_bold">
<item name="android:fontFamily">#font/Cairo-SemiBold</item>
</style>
<style name="cairo_light">
<item name="android:fontFamily">#font/Cairo-Light</item>
</style>
Now you can apply these fonts either in XML or in .java files like this:
Typeface boldFont = getResources().getFont(R.font.cairo_semi_bold);
textView1.setTypeface(boldFont);
Typeface lightFont = getResources().getFont(R.font.cairo_light);
textView2.setTypeface(lightFont);
for changing the font you can use Calligraphy library here!
it's so easy to use
inside your xml fontPath="your font"
refer to the link for the complete guide

Fill color of vector drawables that are icons in dialogs or toolbars

What if I would want to use vector drawables as icons in dialogs or logos in toolbars? Then I would use them like this:
alertDialogBuilder.setIcon(R.drawable.my_vector_drawable);
toolbar.setLogo(R.drawable.my_vector_drawable);
toolbar.setNavigationIcon(R.drawable.my_vector_drawable);
...
Am I right?
But here comes up a question: how can I change their fill color without modifying vector xml files?
For instatnce I can change fill color of any vector that is in view by using 'tint' tag in xml or 'setColorFilter()' method in code.
If you want change fill color not change xml file you must create Drawable instances of this file. This instance get you method to change your file.
for example:
Drawable myIcon = ContextCompat.getDrawable(this,R.drawable.my_vector_drawable);
myIcon.setColorFilter(ContextCompat.getColor(this, R.color.yourcolor));
alertDialogBuilder.setIcon(myIcon);
toolbar.setLogo(myIcon);
toolbar.setNavigationIcon(myIcon);

How to view default android simple_spinner_dropdown_item style

Often i like default android style defined for some widget.
Often i like to just slightly modify this default style, not create my own style from a scratch.
Now, i use android.R.layout.simple_spinner_dropdown_item as dropDownViewResource on my spinner adapter - like this:
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
I can open this layout xml file and copy its content to modify it. But the most important part of that xml file is attribute style, it looks like this: style="?android:attr/spinnerDropDownItemStyle"
Now, my question is: how do i find/view/copy this style spinnerDropDownItemStyle, so i can for example just change background color.
Thanx for your help
here you can find style spinnerDropDownItemStyle:
https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/themes.xml
But, if you looking for change background of Spinner, you'll need to search for 9 patch images:
https://developer.android.com/studio/write/draw9patch.html
And here a good example:
http://www.gersic.com/blog.php?id=57
Ty
My suggestion to you is . you can make a seprate custom layout and put it on your spinner setDropDownResource()
adapter.setDropDownViewResource(android.R.layout.CUSTOM_LAYOUT);
Now you can easily make a style for your layout

Style hierarchy in Android - what is the order of importance?

I have an android application that I'm working on with a custom theme applied to it in the android manifest on the main activity itself. This activity creates a listview, which has the style applied to it.
If I create a custom layout for that listview, including a separate xml file for the rows themselves, and I apply styling directly to those layouts, does this style overwrite the overall style for the application? I'm trying to get a grasp on the hierarchy of events as far as how styling and themeing works.
The way I'm GUESSING it works in my example is: apply style for row, referenced by row layout xml > apply style for overall listview, referenced by listview layout xml > apply style from custom theme, referenced by style xml referenced by android manifest
Am I right? Or am I approaching this incorrectly. (just for confusions sake, by ">" I mean has a greater importance than)
If you've specified the same attributes in multiple places, the list below determines which attributes are ultimately applied. The list is ordered from highest precedence to lowest:
Applying character- or paragraph-level styling via text spans to TextView-derived classes
Applying attributes programmatically
Applying individual attributes directly to a View
Applying a style to a View
Default styling
Applying a theme to a collection of Views, an activity, or your entire app
Applying certain View-specific styling, such as setting a TextAppearance on a TextView
Hope I am understand your question right here...
The styles you define in styles.xml will always overwrite the styles coming from the theme currently used by android.
But this only works for the attributes you overwrite.
If you leave an attribute untouched, android will provide the style for it, and sometimes this comes bite you in the butt :)
This system is best described like this:
A textview requires an attribute example
<item name="android:textColor">#00FF00</item>
Android will first look in the original layout.
If not found, it will look into your custom styles.
If not found, it will look into android styles.
Hope this helps.
The standard themes have lines like which define the ListView style:
<item name="listViewStyle">#android:style/Widget.ListView</item>
In your own theme you can do a
<item name="listViewStyle">#style/MyOwnListView</item>
Something that is not defined in the ListView style (own or default) will be what is defined in the theme if you have defined it there.

Categories

Resources