private void initData() { // 在button上顯示當前用戶名稱 bt_setting_out.setText("退出登錄(" + EMClient.getInstance().getCurrentUser() + ")"); // 退出登錄的邏輯處理 bt_setting_out.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Model.getInstance().getGlobalThreadPool().execute(new Runnable() { @Override public void run() { // 登錄環信服務器退出登錄 EMClient.getInstance().logout(false, new EMCallBack() { @Override public void onSuccess() { // 關閉DBHelper Model.getInstance().getDbManager().close(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { // 更新ui顯示 Toast.makeText(getActivity(), "退出成功", Toast.LENGTH_SHORT).show(); // 回到登錄頁面 Intent intent = new Intent(getActivity(), LoginAcitivity.class); startActivity(intent); getActivity().finish(); } }); } @Override public void onError(int i, final String s) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(getActivity(), "退出失敗" + s, Toast.LENGTH_SHORT).show(); } }); } @Override public void onProgress(int i, String s) { } }); } }); } }); }
用戶名稱變成大寫解決辦法(android:textAllCaps="false")
<Button android:id="@+id/bt_setting_out" android:text="退出" android:textSize="20sp" android:textAllCaps="false" android:textColor="@android:color/white" android:background="@android:color/holo_red_light" android:layout_width="match_parent" android:layout_height="60dp" />