Am trying to set monospace typeface to a listview in my layout but it seems lollipop ignores the set typeface. Other api versions below lollipop works just fine displaying my desired result.
Ps:
Am not trying to set a global font, I just want a monospace texttypeface for my listview for api >21.
Any help will be appreciated.Thanks
EDIT
<ListView
android:layout_gravity="start"
android:id="#+id/List"
android:tag="toggle"
android:background="#99111111"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollingCache="false"
android:typeface="monospace "
android:dividerHeight="0.0dip" />
The Material text appearances specify the android:fontFamily attribute rather than android:typeface.
Try this for global styling,
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:textViewStyle">#style/MonospaceTextViewStyle</item>
</style>
<style name="MonospaceTextViewStyle" parent="android:Widget.TextView">
<item name="android:fontFamily">monospace</item>
</style>
Now simply add the theme to your activity,
<application
android:theme="#style/AppTheme" >
</application>
If your ListView is created with a custom adapter, you may also add the attribute directly inside a TextView,
<TextView
.....
android:fontFamily="monospace"
.....
/>
Related
I am having issues when using android:fontFamily when set via TextAppearance styles.
Setting global font through android:fontFamily in theme works
Setting android:fontFamily directly on TextViews works (I am using AppCompat and it correctly inflates the AppCompatTextView during inflation from xml, so no issues here)
When setting the font via styles, it just does not work. Any help will be much appreciated. I am thinking that this has to do with how AppCompatTextView processes the style attributes, but have not had much luck in finding the exact root cause.
<style name="TextAppearance.Header">
<item name="android:fontFamily">#font/headerfont</item>
</style>
<TextView
android:id="#+id/Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="#style/TextAppearance.Header" />
Try this...hope it will work.
<style name="TextAppearance.Header">
<item name="android:fontFamily">#font/headerfont</item>
</style>
<TextView
android:id="#+id/Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/TextAppearance.Header" />
sometring strange is happening in my app, when I try to change color of ActionBar by
<style name="CustomAppTheme" parent="Theme.AppCompat.Light">
<item name="android:background">#ff00</item>
<item name="android:textColor">#DCDCDC</item>
</style>
is also changes color of my ListView and in other activity changes whole content below. Why is that? How to fix this?
ListView:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/listviewbackground"
android:orientation="vertical" >
<ListView
android:id="#+id/list"
android:longClickable="true"
android:layout_height="wrap_content"
android:layout_width="match_parent">
</ListView>
The documentation is pretty straight forward when it comes to overriding the default color & styles of the action bar. I'm assuming that you're probably making changes to your application's resource styles file at res/values/styles.xml. I'm also assuming that in your AndroidManifest.xml, you have the following property applied to the application tag:
android:theme="#style/AppTheme"
Again, from the documentation:
A style is a collection of properties that specify the look and format for a View or window. A style can specify properties such as height, padding, font color, font size, background color, and much more. A style is defined in an XML resource that is separate from the XML that specifies the layout.
So, when you change that styles.xml file, you're inadvertently changing the background color for all elements in your app.
Follow the instructions from the link 1, and you'll be good. Specifically,
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/actionbar_background</item>
</style>
</resources>
I'm using themes in my application to customize views, and right now everything seems to work fine, except setting android:clipToPadding for a GridView, but what is most surprising is the fact that it works as expected if I set it directly or using a style
My style looks like this (actually I set a lot more parameters but it's irrelevant for this problem):
<style name="GridViewStyle" parent="#android:style/Widget.GridView">
<item name="android:clipToPadding">false</item>
<item name="android:paddingTop">#dimen/grid_item_padding</item>
<item name="android:paddingBottom">#dimen/grid_item_padding</item>
</style>
This is the way I want to set it:
<style name="MyTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="android:gridViewStyle">#style/GridViewStyle</item>
</style>
and all of the parameters work - except mentioned android:clipToPadding
now if I set the style directly:
<GridView
android:id="#id/grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="#style/GridViewStyle"
/>
or if I just set it like this:
<GridView
android:id="#id/grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
/>
then it works.
Does anyone have an idea why style and setting directly is working, but theme is not?
In one of my activities, my EditText views used to look like this
But now they looks like this
I need help changing it back: from the rectangle to the underscore.
BACKGROUND
Because I needed to create a custom ActionBar, I had to change the theme of the activity in question, YesterdayActivity, using the following
Style:
<style name="CustomWindowTitleBackground">
<item name="android:background">#323331</item>
</style>
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">40dip</item>
<item name="android:windowTitleBackgroundStyle">#style/CustomWindowTitleBackground</item>
</style>
Manifest:
<activity
android:name="com.example.YesterdayActivity"
android:theme="#style/CustomTheme">
</activity>
onCreate:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_yesterday);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.yesterday_title_bar);
…
}
Change your custom theme like this
<style name="CustomTheme" parent="android:Theme.Holo.NoActionBar">
because you are not using old android theme not HoLo which has that kinda editTextView
In newer versions of Android, the framework will use the Window.FEATURE_ACTION_BAR feature whenever the Holo theme is selected. The framework throws the exception whenever an app calls setFeatureInt(Window.FEATURE_CUSTOM_TITLE) and FEATURE_ACTION_BAR has already been set.
it crashed because Holo uses the ActionBar by default. The fix was simple. Turn the ActionBar off when using Holo
Remove this line from your style
<item name="android:background">#323331</item>
because it is the background attribute that reflects the behaviour.
There are two ways to achieve this. First method by changing theme of your application
first method:
AndroidManifest.xml
See android:theme
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
...
...
</application>
res/values/style.xml
Theme.AppCompat.Light.DarkActionBar makes underlined EditText
<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>
Just use EditText in same way
<EditText
android:layout_width="match_parent"
android:layout_height="48dp"
android:hint="Email Address"
android:inputType="textMultiLine"
android:textSize="16dp" />
Second method:
Create a shape drawable with bottom stroke and set it as background of EditText
create a drawable file called res/drawable/stroked_edittext_bg.xml said in the below link:
How To Create An Android Shape With Bottom Stroke
<EditText
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#drawable/stroked_edittext_bg"
android:hint="Email Address"
android:inputType="textMultiLine"
android:textSize="16dp" />
it can be achieve, if you change the theme for editText.
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="Name"
android:theme="#android:style/Theme.Holo"
android:ems="10"
android:id="#+id/editText"
android:layout_below="#+id/textView"
android:layout_centerHorizontal="true" />
<item name="android:windowTitleBackgroundStyle">#style/CustomWindowTitleBackground</item>
Change back it to your default style. Or remove this line from code.
Cause the 1st image you shared that is a default Editext background.
I've created a spinner in my activity and when i run my app on my Jelly Bean device the theme of the spinner is like 2.x, how can i get the ICS one?
Here's my spinner code :
<Spinner
android:id="#+id/spinnermap"
style="#android:style/Theme.Holo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" />
As you can see I tried to set the global style "Holo" but no results..
I had the same problem with a NumberPicker but can't remember how I fixed it.
style="#android:style/Theme.Holo"
This is not the solution. You won't have a fallback on pre HC devices.
You need to declare a Theme for your whole application if you want to use the holo theme in your whole app for HC+(I assume this is what you want to have).
In your Manifest:
android:theme="#style/MyTheme"
values/styles.xml:
<style name="MyTheme" parent="android:Theme.Light">
</style>
values-v11/styles.xml:
<style name="MyTheme" parent="android:Theme.Holo.Light">
</style>
Now you'll have a dropdown spinner on HC+(and also other holo widgets of course)
However if you just want to have the spinner to be "holofied" you can do this:
<Spinner
android:id="#+id/spinnermap"
style="#style/MySpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" />
values/styles.xml:
<style name="MySpinner" parent="android:Widget.Spinner">
</style>
values-v11/styles.xml:
<style name="MySpinner" parent="android:Widget.Holo.Spinner">
</style>