WebView change height Android Example
The Android WebView changing the height according to text size.
If you need to change the height to a minimum try this source:
If you need to change the height to a minimum try this source:
//public void loadDataWithBaseURL (String baseUrl, String data, String mimeType, String encoding, String historyUrl)
WebView _webView; // findById(.....
String entryContent = "";
_webView.loadDataWithBaseURL(
"blabol",// javascript i styly
entryContent, null,
"utf-8", null
);
396LW NO topic_id
AD
Další témata ....(Topics)
StringBuilder, res/raw folder, try catch finaly throws, BufferedReader, InputStream, openRawResource, getResources Android example
MainActivity.java
MainActivity.java
public class MainActivity extends Activity {
TextView txtV;
Context cntx;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtV = (TextView)findViewById(R.id.idLabel);
cntx = this;
try {
StringBuilder strBuilder = myFunction(cntx);
txtV.setText(strBuilder);
} catch (IOException e) {
e.printStackTrace();
}
}
private StringBuilder myFunction(Context context) throws IOException {
final Resources resources = context.getResources();
InputStream inputStream = resources.openRawResource(R.raw.my_file);
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder strBuild = new StringBuilder();
try {
String line;
while ((line = reader.readLine()) != null) {
strBuild.append(line);
}
} finally {
reader.close();
}
return strBuild;
}
}
Generate random number Android Java example source code.
Random rand = new Random();
int i = rand.nextInt() % 256; // range -255 +255
System.out.print(i + "
"); // -184
i = Math.abs(rand.nextInt() % 12); // range 0 +11
System.out.print(i); // 7
// Math.random() start with 0. e.g. 0.35981234
int nRan = (int) (Math.random()*10); // 0 - 10
// nextDouble(), nextFloat(), nextInt(), nextLong() returns 0 - 10
import java.util.Random;´
Random r = new Random();
int nRan = r.nextInt(); // 0 - 10
double dRan = r.nextDouble() * 10; // e.g. 7.496285271597397
nextDouble – return 0 - 1
nextFloat – same as double
nextInt – -2147483648 +2147483647
nextLong – -922337203685775808 +9223372036854775807
nextGaussian – 0.0 aberation 1.0.
Convert number int to string Android Java example source code.
int n = 0;
try {
n = Integer.parseInt("21"));
} catch(NumberFormatException e) {
System.out.println("Could not parse " + e);
}
// int to string
String s = String.valueOf(24);
// warning
private static String DB_PATH = "/data/data/cz.okhelp.german_czech_phrases/databases/";
// OK
public DataBaseHelper(Context context) {
super(context, DB_NAME, null, 1);
this.myContext = context;
// OK
DB_PATH = context.getFilesDir().getParentFile().getPath()
+ "/databases/";
}
How get application version, sdk version, package name defined in the AndroidManifest file programmically Android sample.
MainClass.java onCreate()
AndroidManifes.xml
MainClass.java onCreate()
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// in onCreate
PackageInfo pinfo = this.getPackageManager().getPackageInfo(getPackageName(), 0);
String sVersionCode = pinfo.versionCode; // 1
String sVersionName = pinfo.versionName; // 1.0
String sPackName = getPackageName(); // cz.okhelp.my_app
int nSdkVersion = Integer.parseInt(Build.VERSION.SDK); // 7
int nSdkVers = Build.VERSION.SDK_INT; // 7
}
AndroidManifes.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="//schemas.android.com/apk/res/android"
package="cz.okhelp.my_app"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Add_view_to_tableActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Editace: 2012-01-07 09:00:43
Počet článků v kategorii: 396
Url:webview-change-height-android-example