I have been attempting to create a simple TabActivity with 3 Tabs. All works except if I put android:minSdkVersion="11" in the Manifest file, the icons are not shown. If I set `minSdkVersion="10", all is well.
I have looked high and low, but I have not been able to determine what is wrong.
I have put the same images in the seemingly appropriate resource directories:
res/drawable-hdpi-v5
res/drawable-ldpi-v5
res/drawable-mdpi-v5
res/drawable-xhdpi-v5
And the the code is simple:
import android.app.TabActivity;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabWidget;
public class Review extends TabActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TabHost tabs = getTabHost();
getLayoutInflater().inflate(R.layout.main,
tabs.getTabContentView(), true);
Resources resources=getResources();
Log.d("testing", String.format("icon: %d.%d",
resources.getDrawable(R.drawable.review).getIntrinsicWidth(),
resources.getDrawable(R.drawable.review).getIntrinsicHeight()));
TabHost.TabSpec details = tabs.newTabSpec("review"). setContent(R.id.review).
setIndicator(getString(R.string.review),
resources.getDrawable(R.drawable.review));
TabHost.TabSpec gallery=tabs.newTabSpec("gallery").setContent(R.id.photos)
.setIndicator(getString(R.string.gallery),
resources.getDrawable(R.drawable.photos));
TabHost.TabSpec reservation=tabs.newTabSpec("reservation").
setContent(R.id.reservation)
.setIndicator(getString(R.string.reservation),
resources.getDrawable(R.drawable.reservation));
tabs.addTab(details);
tabs.addTab(gallery);
tabs.addTab(reservation);
}
}
In digging into this, the only difference I can see internally under android 2.0 vs 3.0 is that Android uses a RelativeLayout instead of a LinearLayout in the 2.0 implementation.
Just to be certain that the icons images are being found, Log.d of above shows:
icon: 32.32 as it should.
Why does this shift from android 2.0 to 3.0 do this???? I am hopeful that someone else has run into this and it is obvious. Thanks very much for your help!
-- UPDATE:
I discovered today, as I looked more closely at what is actually happening when this code is built for android 3.0+, I learned that the ImageView's that come about when SetIndeicator(string, drawable) is called for each TabSpec, are actually never set and are actually NULL (ImageView.mDrawable==null) and INVISBLE.
If I force set those drawables to be set, and call ImageView.setVisiblity(View.VISIBLE) then they show up. However under android 2.0 they appear stacked with the image above and the text below as in:
<image>
<text>
Under android 3.0 they appear (when forced as above) side by side as in:
<image><text>
Thus it seems that things have changed a great deal and I need to investigate the changes for android 3.0 more carefully.
Stay tuned for more...
-- Final UPDATE:
Ultimately, I abandoned this avenue and decided that this style of doing things changed and is perhaps now depreciated and there are other better ways to do this and the icons are a bit old style.
strange, this solves the problem
//bmOptions.inSampleSize = 1;
//or better
bmOptions.inScaled = false;
more at:
https://stackoverflow.com/a/12088287/1320686
Related
I am developing an Ionic 3 application, I recently published it and in production, where phones of all kinds and sizes were used, I noticed that there is an android native setting called "font-size" where you can make the size of texts in your phone bigger or smaller.
Some people (among others many older people) choose 'big' or even 'huge' text size. This unfortunately affects texts in my application on their phones and completely ruins the layout.
The way I am defining font sizes in my css files is with em values, but I also tried px.
Do you know if there is any way to prevent my application from adhering to this native android text-size setting? Or any other ways to fix it?
Please help,
Cheers
I found the solution! I used this phonegap plugin:
https://ionicframework.com/docs/v3/native/mobile-accessibility/
and used the method this.mobileAccessibility.usePreferredTextZoom(false);
This way, my app ignores the android font size settings!
I face similar issue. I have done as below for best practice :
this.platform.ready().then(()=>{
this.mobileAccessibility.getTextZoom().then((textZoom)=>{
if(textZoom>130){
this.mobileAccessibility.setTextZoom(130);
}
});
})
Setting text zoom with JS works with a jump from big to small size. But in MainActivity.java it applies immediately without visible delay
package io.ionic.starter;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import com.getcapacitor.BridgeActivity;
public class MainActivity extends BridgeActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView mWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setTextZoom(100);
}
}
The plugin suggested in the accepted answer was last updated in 2016. Instead of adding a new plugin, we can configure the webview settings to disable text zoom as discussed here.
So, inside MainActivity.java you can do something like this:
import com.getcapacitor.BridgeActivity;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class MainActivity extends BridgeActivity {
public void onResume() {
super.onResume();
WebSettings settings = bridge.getWebView().getSettings();
settings.setTextZoom(100);
settings.setSupportZoom(false);
}
}
I updated Visual Studio, then my Android project had errors such as import could not be resolved. It could not be resolved to a text type. The type could not be resolved. Then I created a new project with the same settings. However, it had the same errors. It does not work because of the code, but maybe it knows who knows the code here.
package com.Android2;
import android.app.Activity;
import android.widget.TextView;
import android.os.Bundle;
public class Android2 extends Activity
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
/* Create a TextView and set its text to "Hello world" */
TextView tv = new TextView(this);
tv.setText("Hello World!");
setContentView(tv);
}
}
There is no problem with your code or imports...
I know it is hard work and a serious change when it comes to shortcuts, menus, overview, etc., but i would suggest to use android studio instead of visual studio if you only write android apps in java. I used visual studio too and switched to android studio.
Android Studio will give you more comfort than every other ide in programming android apps in java!
I know this problems you wrote about very well and had the same. Sry that this isnt a really answer of your problem and does not solves your concrete problem.
Tips for solving, you probably already know:
reboot your pc and visual studio if you not already did
delete caches or other from visual studio
rebuilt/clean your project
not easy, but reinstall visual studio
I hope i could help anyway!
In Ice Cream Sandwich, when there's an Activity containing an EditText, the EditText will retain the Activity's Context even after the user leaves the Activity. To demonstrate this I've created TestLeakActivity, which allocates a large byte array. Since the Activity's Context is never garbage collected, the byte arrays accumulate on the heap, eventually causing an OutOfMemoryError. You can observe the heap growth by using the DDMS heap tool, and you can track the outstanding references to the EditText class by looking at the HPROF file in Eclipse MAT. To create memory leaks, go into LaunchActivity and just keep launching and backing out of TestLeakActivity.
LaunchActivity.java
package com.example.testleakproject;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
public class LaunchActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button button = new Button(this);
button.setText("Start TestLeakActivity");
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(LaunchActivity.this, TestLeakActivity.class);
startActivity(intent);
}
});
ViewGroup container = ((ViewGroup) findViewById(android.R.id.content));
container.addView(button);
}
}
TestLeakActivity.java
package com.example.testleakproject;
import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.EditText;
public class TestLeakActivity extends Activity {
private byte[] mSomeBytes = new byte[1048576];
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EditText editText = new EditText(this);
editText.setHint("TestLeakActivity");
ViewGroup container = ((ViewGroup) findViewById(android.R.id.content));
container.addView(editText);
}
}
This is a known bug, that will be fixed in ICS MR1.
This has not been fixed until now. (Android 4.2.1)
I've just spend several hours to find that I'm affected by this issue.
The issue seems to be caused by the spell checker. When I disable suggestions for the EditText view everything is properly garbage collected.
mInputType = mText.getInputType();
mText.setInputType(mInputType | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
I don't really want to disable this, since many users want spell checking. So, maybe there is a way to temporarily enable it when the input field receives the focus.
If you don't need the spell checker just add this to the EditText element in your layout xml instead:
android:inputType="textNoSuggestions"
That seems to fix it too.
Edit:
Just found this thread that appears to be related: Work around SpellCheckerSession leak?
I'm experiencing the same. My Gingerbread devices all work fine, but testing on my Galaxy Nexus this situation arises predictably. What your experiencing is likely why the MR1 and 4.0.3 updates rolled out so quickly.
You are running into the situation described in the Android resources section on memory leaks. See that page for some solutions as well.
I got the same problem,
I solved it by hiding the EditText ondismiss of my dialog.
mEditText.setVisibility(View.GONE);
First off, as background: I am on a Mac, running OS X 10.6.7. Using Eclipse for an Android Development class I'm in (and hopefully eventually to actually develop directly for Android).
I had a nasty crash of Eclipse a few days ago, and after restarting I stopped getting any output from LogCat whatsoever. I tried everything I could think of, and I couldn't get anything at all to show up in the log. I tried a nuke-it-from-orbit reinstall of Eclipse, and it's at least made a little bit of a difference. When I run this code snippet I came up with to test things:
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class LogTester extends Activity {
/** Called when the activity is first created. */
public static final String TAG = "LogTester";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d(TAG, "Activity was created");
Log.d(TAG, "Anybody Home?");
}
}
...it shows me this (apparently I can't post images directly as a noob), but when I actually click on the LogTester tab of LogCat, I see nothing. The same thing vice-versa when I click back over to the main log tab, which as you can see should have 11 new items in it.
I tried changing the font since maybe there was some sort of issue with displaying the font, and I've heard there are weird issues with fonts and 10.6.7. But I get a "Problems occurred when invoking code from plug-in: "org.eclipse.ui.workbench"." error and a complete refusal to change the font type. I can't figure out where Eclipse hides this preference so I can try and fiddle with it manually.
Anyone have any ideas/suggestions as to things I should try next? This is absolutely maddening. Thanks!
UPDATE (3/31 1am): I deleted and recreated my AVM for about the 15th time and LogCat suddenly started working. Hell if I know why, but I'm not questioning it.
try switching to DDMS perspective and click on your active emulator in the Device tab. Your Logcat should refresh then.
I know this post is old but a filter got turned on for some reason using Firebase which really confused me for a few mintues while I tried to figure out what was going on.
Here's where you change the filter (in the android monitor panel):
I have a simple Android app that targets Android 1.5 or above. I have an activity that is set to use the theme below (set in the manifest).
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
Within the activity, I have a WebView (see full XML:)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
I believe I have my onCreate code setup to properly handle urlLoading (see below). In the emulator when I test this code, the status bar does no display at the top. On my target device which is an Archos 7 home tablet running Android 1.5 with a screen resolution of 800 x 480, the app runs, but the status bar appears at the top.
Any idea why this might be happening?
FULL SOURCE OF THE main activity:
package com.bri.RestaurantLauncher;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class RestaurantLauncherMain extends Activity {
private class RestaurantLauncherMainWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
}
WebView webview;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
this.webview = (WebView) findViewById(R.id.webview);
webview.setWebViewClient(new RestaurantLauncherMainWebViewClient());
this.webview.getSettings().setJavaScriptEnabled(true);
this.webview.loadUrl("http://www.google.com");
}
}
Any idea why this might be happening?
If I had to guess, it is tied to this:
On my target device which is an Archos
7 home tablet...
Tactically, the ARCHOS 7 tablet appears to work like the ARCHOS 5, with the HOME, BACK, and MENU buttons on the status bar. In that case, the ARCHOS riff on Android may not support full-screen mode, because then the user could not leave the app. You might try some existing open source projects known to support full-screen mode and see how they behave. For example, my vidtry sample app plays back streaming video full-screen.
Strategically, always ensure that your primary test device has the Android Market installed. Devices that have the Market must pass compatibility checks, other devices do not. Now, if you want to have a non-Market device just for some light testing, that's cool, but you will want some other Market-enabled Android device to see what the experience will be like for the vast majority of Android users.
Thanks. I'm still looking around for a way to do this. Some apps that come with the device (video) do hide the status bat, but at least so far, I haven't been able to do so. I'm not looking to build a consumer app for end users, so Market access isn't that important at this point. The ultimate app would be sold together with the hardware as a turnkey solution. If I can't get it to work on the Archos 7 I'll have to resort to an imported no brand Chinese device. I'd rather not do that due to the additional expense involved. The Archos seems to be well made, has good battery life and a decent touchscreen for my needs.