我必须分三个部分显示文本,所以我使用了Html.fromHtml,如下所示:
txtvw.setText(Html.fromHtml("<p align=right> <b> "
+ "Hi!" + " </br> <font size=6>"
+ " How are you "+"</font> </br>"
+ "I am fine" + " </b> </p>"));
Run Code Online (Sandbox Code Playgroud)
HTML是正确的,但在设备中它显示在一行.
我的textview xml声明是:
<RelativeLayout
android:id="@+id/Home"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:background="@drawable/transparentfooter"
android:layout_above="@+id/bottombar" >
<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="@android:color/white"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 我在资产中有一个html文件,aaa.html.我想读取html文件的内容并将其替换为另一个字符串.
这种方式是对的还是有其他选择.
我的代码:
File f = new File("file:///android_asset/aaa.html");
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
Run Code Online (Sandbox Code Playgroud)
但是找不到给定文件,在web视图中加载文件时加载文件.
我想存储/保存整个应用程序,即创建备份,以便在需要时,能够恢复相同的先前应用程序状态.可以使用备份管理器或任何其他方式完成.
我发布了一个带有下划线(_)的参数的网址.
样品: http://sdsdsds_asasasahjhd.com/dsdsdsd/login.json?
我发布的方式如下:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://sdsdsds_asasasahjhd.com/dsdsdsd/login.json?");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("key1", "value1"));
nameValuePairs.add(new BasicNameValuePair("key2", "value2"));
nameValuePairs
.add(new BasicNameValuePair("key3", "value3"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (Exception e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
当我正在检查时,httpclient.execute(httppost)我正在IllegalArgumentException接收异常详细信息Host name cannot be null.请指明任何解决方案.
我在这里经历了一些其他问题:
但没有用,因为我没有编码整个网址.
我想阅读存储在我的SD卡中的pdf文件,我尝试使用这个片段
File file = new File(Environment.getExternalStorageDirectory()
+ "/vvveksperten" + "/ypc.pdf");
PackageManager packageManager = getPackageManager();
Intent testIntent = new Intent(Intent.ACTION_VIEW);
testIntent.setType("application/pdf");
List list = packageManager.queryIntentActivities(testIntent,
PackageManager.MATCH_DEFAULT_ONLY);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(file);
intent.setDataAndType(uri, "application/pdf");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
但它给了我一个错误.
ERROR/AndroidRuntime(2611): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///mnt/sdcard/vvveksperten/ypc.pdf typ=application/pdf }
Run Code Online (Sandbox Code Playgroud) 我用这个压缩了图像:
private Bitmap decodeFile(InputStream is){
//decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(is,null,o);
//Find the correct scale value. It should be the power of 2.
final int REQUIRED_SIZE=100;
int width_tmp=o.outWidth, height_tmp=o.outHeight;
int scale=1;
while(true){
if(width_tmp/2<REQUIRED_SIZE || height_tmp/2<REQUIRED_SIZE)
break;
width_tmp/=2;
height_tmp/=2;
scale*=2;
}
//decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize=scale;
return BitmapFactory.decodeStream(is, null, o2);
}
Run Code Online (Sandbox Code Playgroud)
我在图像视图中设置此位图,但它在顶部和底部留下了一些空间.
我试过这个:
img.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,FrameLayout.LayoutParams.MATCH_PARENT));
img.setImageBitmap(bm);
Run Code Online (Sandbox Code Playgroud)
但没用
还有其他方法吗?