android:fontFamily is only working with AppCompatTextView - android

I was moving my project drop Calligraphy and use the native android android support for fonts. However, I can only make it work if I use AppCompat elements instead of the default ones (TextView, Button, etc..). I wanted to know if this is expected and if not, how could I solve it?

So I figured it out:
The problem was that in on of the legacy BaseActivity#onCreate we were calling setContentView before the call to super.onCreate(). By doing this it will somehow disable the font from being correctly rendered.

Related

Which Compact Views is correct to use directly?

In some view like AppCompatTextView we can read
This will automatically be used when you use EditText in your layouts
and the top-level activity / dialog is provided by appcompat. You
should only need to manually use this class when writing custom views.
But sometime not, like LinearLayoutCompat
So this means that we should use LinearLayoutCompat directly instead of LinearLayout ?
In case, which Compact Views is correct to use directly?
So this means that we should use LinearLayoutCompat directly instead
of LinearLayout ?
The answer is Yes.
which Compact Views is correct to use directly?
You should be able to use all the Compat views directly without any issue. AFAIK...They are built to provide more compatibility and they tend to be updated more frequently as almost all of them come from Support or AndroidX libraries which receive more frequent updates.

No shadow on absolutely positioned View/Image?

I did a materalistic designed "Add" button on my Android-primary react-native app. While I used elevation style property as a primary source for shadows in the rest of the elements, I've discovered that it stops working when applied to an absolute positioned element. (Which I partially understand probably because absolutely positioned element ignores the general layout rules, but still, a shadow should work).
As far as I know, Android gets elevation and iOS gets their respective shadow properties.
I'd like to have this:
but I 'm getting no shadow once I set the element's style as absolute (in the bottom right corner).
Am I missing something or is it not working yet?
Simply, there is no current shadow support for Android in React Native yet and I think you are on the right track to use elevation way to achieve this. But it should only work for Android 5.0 or above.
Alternatively, you can try this module (https://github.com/879479119/react-native-shadow). It works for me.

Android: Support Fragments don't apply activity theme?

At the moment, I'm stuck with a very annoying kind of "bug" I assume regarding all Pre-Lollipop Android versions. It appears that (support) fragments don't apply the activity's theme they're assigned to. To make my explanations a bit easier, have the following demonstration:
My app runs with a turquoise theme at first. Let's say, the user decided to change the turquoise theme to a red theme. He or she restarts the app and is greeted with the following:
(screenshot taken on an Android 4.4.2 tablet)
Terrible sight, isn't it? However, if I run the same app in an emulator with Android L the whole theme problem doesn't even seem to exist.
There's especially one thing which seems odd about the tablet screenshot. The fragment itself doesn't apply the theme but child components inside the fragment which get added lateron (like the view with the exclamation mark which is hosted by a ViewPager) take and apply the theme as if nothing happened.
I'm not quite sure what the issue might be. I've done everything as stated in every document available. I set the theme before I call setContentView(resource) in the corresponding activity. I tried to do the trick with ContextThemeWrapper but it was no use.
Relevant code:
The activity's onCreate()
The fragment's onCreateView()
The fragment's layout
Attributes
Themes (a lot of them)
I tried to resolve this issue for days now and I still can't find out why this is not working. I haven't found a suitable answer yet and would love some advise.
I've been the victim to my own stupidity. I had another close look on my project setup and found this:
My tablet takes its layout resources from the sw600dp-folder, but I forgot to change the corresponding layout to take attributes instead of hardcoded colors. I think I have to retire after making such a stupid mistake.

Customizing a project library in Android

I'm using this library project in my Android application. But I need to make some customization for it.
For example, if I need a EditText instead of the provided TextView, what is the best practice to customize the library for my needs without writing code in the Project Library?
I made this customization by defining in the library's actionbar.xml layout a EditText instead of TextView, but I don't like this approach.
Do you have any guidelines, tutorials that could help me out?
In your special case I would suggest to use original compatibility's-package actionBar.
But to answer your question: you could always extend classes from the Library, which I think is the best practice if the library should kept untouched. Overriding Methods which you want to change their behavior keeps anything clean. You do the exact same every time you extend android-sdk classes, which you cannot change like you want.
In the case of changing layouts I'm not quite shure. I think I can remember that if the lib has an actionbar.xml and you have an actionbar.xml inside your project, too, yours will win. just like an "overriding layouts" feature

How do I use common UI styles in Android?

I am writing my little Android app. I pop up a dialog control which is a nice, non-fullscreen, rounded-corners dialog by setting android:theme="#android:style/Theme.Dialog" on the activity in my manifest. That all works just as I expected. However it is just a drab, grey-titled dialog as in this screenshot:
I've noticed however that a LOT of applications, when they pop up dialogs have a nice, blue-themed title as in this screen shot.
I would assume this theme is some common theme, as it shows up in a LOT of different apps. I would assume it is something built in to the OS. (My phone is a Captivate with the official Froyo release). Of course it COULD be something that every developer simply re-coded on their own, but I doubt that.
Assuming that this is a common theme, how do I utilize it in my app? What changes do I need to make to my activity to have it use that theme?
Thanks in advance!
You can set your activity to use a default theme like Theme.Black. There are default themes and they are in R.style - although i'm not sure which are available to which platforms(i.e. i think the holo themes are for 3.0 and up...
http://developer.android.com/reference/android/R.style.html
see here http://developer.android.com/guide/topics/ui/themes.html for defining your own custom themes and scroll all the way down for using the "platform styles" and themes.
Rather messy (there doesn't seem to be a good reference for this), but the platform styles are defined in \platforms\android-\data\res\values\styles.xml and \platforms\android-\data\res\values\themes.xml. You can dig through those and figure out the theme/style IDs that are available at compile time.
Other than that its really just trial and error.
To make a dialog you need to extend the dialog class. And to have a nice title bar you can use:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
and have your own custom title.
to have a title use:
setTitle("MyTitle");
You can also assign your custom view for the title.

Categories

Resources