实际上,我需要读取一个utf8格式的字符串,但它的字符使用可变长度编码,所以我有问题将它们编码为字符串,打印时我得到奇怪的字符,字符似乎是韩文这是我使用的代码,但没有结果:
public static String byteToUTF8(byte[] bytes) {
try {
return (new String(bytes, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
Charset UTF8_CHARSET = Charset.forName("UTF-8");
return new String(bytes, UTF8_CHARSET);
}
Run Code Online (Sandbox Code Playgroud)
我也使用了UTF-16并获得了更好的结果,但是它给了我奇怪的字符,根据上面提供的文档,我应该使用utf8.
在此先感谢您的帮助.
编辑:
我正在尝试使用ScrollView和Toolbar作为LinearLayout的唯一子项,但它们相互重叠.搜索了一下,但没有找到任何有用的,任何想法如何解决这个而不是给ScrollView填充/边距?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:float="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="right"
android:background="@color/white_dark_50">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toolbar"
android:theme="@style/AppTheme"
android:scrollbarStyle="outsideOverlay"
android:gravity="center_vertical|right"
android:layout_alignParentTop="true"
android:background="@color/colorPrimary"
>
<!-- -->
</android.support.v7.widget.Toolbar>
<ScrollView
android:scrollbarStyle="outsideOverlay"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_gravity="center"
android:background="@color/white_dark_50" >
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="right"
android:background="@color/white_dark_50">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="????? ???? ????"
android:id="@+id/new_sentence_title"
android:textColor="@color/midnight_blue"
android:layout_margin="10dp"
android:textStyle="bold"
android:gravity="center_vertical"
android:drawableRight="@drawable/ic_colored_doll"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
<View
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_marginLeft="25dp"
android:layerType="software"
android:layout_marginRight="25dp"
android:background="@drawable/dashed_line" />
<com.wrapp.floatlabelededittext.FloatLabeledEditTextRightSided
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_marginBottom="5dp"
float:fletPaddingLeft="10dp"
float:fletPaddingRight="10dp"
android:id="@+id/new_sentence_name"
float:fletPadding="10dp">
<EditText
android:layout_marginLeft="10dp"
android:id="@+id/new_sentence_name_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme" …Run Code Online (Sandbox Code Playgroud)