Set a values folder for multiple android sdk versions - android

I would like to set a values folder for multiple sdk verions to set a theme for everything under sdk 19. I have tried doing:
protected void onCreate(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT < 19) {
getApplication().setTheme(R.style.HomeTheme4);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_launch_screen);
[.....]
}
But this doesnt seem to set the theme For the whole app.
Thank you in advance.

you could place your theme that you want to use for API-19 and above inside the folder:
/values-v19
and the default values folder then will handle everything below API-19:
/values
see related android resource qualifiers documentation.

Related

Xamarin - working with VectorDrawable in Imageview and Edittext

I face issue to apply vectordrawable at my imageView and Edittext
here is my tries to fix the issue
First I am using Xamarin.Android.Support.Vector.Drawable Version 23.4.0
Second I add AppCompatDelegate.CompatVectorFromResourcesEnabled = true; in onCreate of my Application
public class MyApplication : Application
{
public MyApplication(IntPtr handle, JniHandleOwnership ownerShip) : base(handle, ownerShip)
{
Log.Debug("App", "I am in oncreate application");
}
public override void OnCreate()
{
base.OnCreate();
AppCompatDelegate.CompatVectorFromResourcesEnabled = true;
}
}
*Third * usingAppCompatActivity to make sure my activity used AppCompatImageView instead of normal ImageView and try set drawable manually but it return with null (I dont know why this happen )
[Activity( Label = "Activity1", Theme = "#style/AppTheme")]
public class Activity1 : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.test);
ImageView testImage = FindViewById<ImageView>(Resource.Id.imageViewTest);
Drawable drawable = VectorDrawableCompat.Create(Resources, Resource.Drawable.ic_arrow_back_white_24dp, null);
testImage.SetImageDrawable(drawable);
}
}
Fourth in my project .csproj I add build tools version 23.0.3
<AndroidSdkBuildToolsVersion>23.0.3</AndroidSdkBuildToolsVersion>
here is my full file content
?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AndroidSdkBuildToolsVersion>23.0.3</AndroidSdkBuildToolsVersion>
<AndroidDesignerPreferredDevice>Nexus 4</AndroidDesignerPreferredDevice>
<SelectedDevice>Nexus_5_API_21_x86</SelectedDevice>
<AndroidDesignerPreferredTheme>Theme.DeviceDefault</AndroidDesignerPreferredTheme>
</PropertyGroup>
</Project>
Fifth I reference my vector image app:srcCompat
but it still not working any one could help me fix this issue
I fix first half of my issue Simplly update to
Xamarin.Android.Support.Vector.Drawable Version 23.4.0.1
make sure you reference your vector images by this way app:srcCompat
related to EditText Image I think you cant set it from xml you need to use it via code here is the method
SetCompoundDrawablesWithIntrinsicBounds(Drawable left, Drawable top, Drawable right, Drawable bottom);
in my case I used leftdrawable so my method look like
SetCompoundDrawablesWithIntrinsicBounds(Resource.Drawable.MyDrawable, 0, 0, 0);
hope this help any one face same issue
Update: Forget the Old Solution. Just update to the latest Verison of Xamarin (Xamarin.Android 7.2.0.7) and the latest version of the support libs (25.3.1).
Old Solution:
Downgrade to Xamarin 4.2.0.680, use only the support libs version 23.3.0 (Latest stable 24.2.1 crashes on Android 4.4.4 but works on Android 6)
Also ensure this:
Put this static constructor in your Activity:
static Activity1()
{
AppCompatDelegate.CompatVectorFromResourcesEnabled = true;
}
Or add AppCompatDelegate.CompatVectorFromResourcesEnabled = true; to your Application class´ OnCreate method.
<AndroidSdkBuildToolsVersion> in your project shouldn't be nessessary anymore.
Use app:srcCompat, like you already do.
Have a look at the Dependencies of each support lib at Nuget
I have:
Xamarin.Android.Support.Animated.Vector.Drawable.dll 23.3.0
Xamarin.Android.Support.Design.dll 23.3.0
Xamarin.Android.Support.v14.Preference.dll 23.3.0
Xamarin.Android.Support.v4.dll 23.3.0
Xamarin.Android.Support.v7.AppCompat.dll 23.3.0
Xamarin.Android.Support.v7.Preference.dll 23.3.0
Xamarin.Android.Support.v7.RecyclerView.dll 23.3.0
Xamarin.Android.Support.Vector.Drawable.dll 23.3.0
Also make shure you reference Java.Interop.dll
Try out another vector drawable, for example from Material Design Icons (Click on an icon, chose Icon Package, .XML Vector Drawable).

AVD ignoring layout-large/file

I chose my emulator as a Nexus 7 through Android Studio.
It's size is "large".
But when I run my app on the emulator then it still prefers using the default "layout" folders resource files.
I tried using the "layout-sw600dp" qualifier but still with no luck.
The resource file in both layout folders have the same name "news_articles.xml".
See my basic code below:
public class MainActivity extends Activity implements HeadlinesFragment.OnHeadlineSelectedListener{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.news_articles);
}
What am I missing?
You should change in AVD Manager - Your Emulator Edit - Show Advanced Setting - Custom Skin Definition to "No Skin" and rerun the emulator.

Cannot build a new Android Applications project on ubuntu with Eclipse IDE

I am trying to build a project but when create this error display.
[2015-04-12 11:38:25 - Em] /xxx/xxxxx/workspace/Em/res/values-v14/styles.xml:8: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBa
r'.
I do not have idea what Can be this issue but all source mark acces error to source "R." Like this.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_echile);-->Error "R."
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
It's not a Ubuntu nor Eclipse problem. The error is indicating, that SDK can't find required resource, and it is an AppCompat resource, which means that it included in a support library. You need to add it manually, instruction you can find here.
If you have already imported it, but it doesn't work, you may try this approach.
It seems like, you have chose, when creating Android project, to use Dark Theme. Sometimes happens, that Theme resources not loaded automatically. If it is not critical to you, which theme to use, you can always choose None theme, cause it don't need to load additional resource.

how to set background xml file in drawable for a view?

how can I set an xml background file that placed in drawable for a view without using #SuppressLint("NewApi") ?
for example I created a drawable xml file for my textview
when I call TV.setBackground(getResources().getDrawable(R.drawable.tv_pic_back)); eclipse automatically add #SuppressLint("NewApi") at the first of my function.
how can I use that without #SuppressLint("NewApi") ?
I have a class where I put a lot of code to handle the different APIs, so that you use one line of code for one API, and another line of code for another API.
public static void setBackgroundDrawable(View view, Drawable drawable) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.setBackground(drawable);
}
else {
view.setBackgroundDrawable(drawable);
}
}
This will still give you a warning because setBackgroundDrawable is deprecated, but if you instead would use setBackground(drawable) for all versions then your application would crash on API levels lower than Jelly Bean (API 16).
However, in your case all you need to do is actually setBackgroundResource(R.drawable.tv_pic_back); because you don't need to get the drawable from the resource id yourself, Android will do that for you if you give it your resource id when you call the right method.
The Android developer reference will tell you which methods are deprecated and which methods are implemented in which API version.

textStyle for Tamil font?

I'm already working on an Android application that displays RSS feed.
My problem is that this feed has some lines in Tamil(which Android still doesn't support)
I found a font online that displays the text right(without converting to Bamini) but the problem is that textStyle doesn't have any effect on it.
so you know any font that can do the job or any thing i have to do to make textStyling?
thanks in advance
What you need to do is import custom fonts on to the phone before using them.
A good way to do that is to include them in the package - in the APK file
Hence you should be having the font in your project when you build the APK file.
Let me give you an example. Assuming your tamil font's name is Harabara.ttf and you have copied it to /assets/fonts
Use this method (anywhere in your activity)
private void initializeFonts() {
font_harabara = Typeface.createFromAsset(getAssets(), "fonts/Harabara.ttf");
}
and call this API from your onCreate like this
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initializeFonts();
setContentView(getViewResourceId());
}
Make sure you have declared this class level variable
Typeface font_harabara = null;
Finally, simply use
myTextField.setTypeface(font_harabara);
tada ! tamil font should now start displaying.
nandri vanakkam,
vaidyanathan
There are hundreds of fonts available online. Did you check some TSCII fonts?
I've written some solutions for Tamil and Android issues. Check it out too.

Categories

Resources