我有一个没有子窗口小部件的活动,相应的xml文件是,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable="true"
>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我想在活动开始时以编程方式打开软键盘.我现在尝试的是,
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
Run Code Online (Sandbox Code Playgroud)
给我一些指导.
我正在尝试在一个按钮内使用两个带有不同字体的TextView自定义按钮.为此,我只是扩展了Button并在构造函数中编写了以下代码,
LayoutInflater layoutInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.custom_button,
(ViewGroup) findViewById(R.id.custom_button_view));
TextView firstTextView = (TextView) layout
.findViewById(R.id.firstTextView);
TextView secondTextView = (TextView) layout
.findViewById(R.id.secondTextView);
Run Code Online (Sandbox Code Playgroud)
在布局custom_button我已经放置了两个具有不同字体和文本的TextView,custom_button_view是该LinearLayout的ID,我得到的是一个没有文本的空按钮.
任何想法,谢谢.
在链接字符串资源中我发现Android只支持使用HTML标记的粗体,斜体和下划线样式,我看到一些应用程序在AlertDialog中显示无序列表,所以试图在我的应用程序中实现它
在我的String.xml中,我已经给出了
<String name="unorderedlist">Different Types <ul> <li>T ype 1 </li> <li> Type 2 </li> </ul> </String>
Run Code Online (Sandbox Code Playgroud)
在我的活动中,我尝试在AlertDialog中显示它,如下所示
String formatedString=String.format(getResources().getString(R.string.unorderedlist), "");
myAlertDialogBuilder.setMessage(Html.fromHtml(formatedString));
Run Code Online (Sandbox Code Playgroud)
它没有用,所以还有其他方法可以做到这一点,给我一些指导.提前致谢.
我只是想尝试使用不同的复选框,其外观看起来像一个单选按钮,就像一个内部带有绿灯的圆形按钮.我用Google搜索了很长时间,但没有找到解决方案,有没有办法做到这一点.
提前致谢.
在我的服务器应用程序中,我试图处理使用 ServerSocket 的服务器,例如,
我可以启动服务器并使其在线程内等待客户端
socket = serverSocket.accept();
Run Code Online (Sandbox Code Playgroud)
我想要做的是我想手动关闭正在等待连接的套接字,我尝试过使用,
if (thread != null) {
thread.stop();
thread = null;
}
if (socket != null) {
try {
socket.close();
socket = null;
}
catch (IOException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
执行上述代码后,即使套接字变为空,当我尝试从客户端连接到服务器时,连接就会建立,所以我的问题是如何中断在这里侦听连接的服务器套接字,
socket = serverSocket.accept();
Run Code Online (Sandbox Code Playgroud) 我正在尝试从 Android 应用程序覆盖文本文件,我已经做了的是,
我在一项活动中使用以下方法创建了一个文本文件:
FileOutputStream create_file = null;
OutputStreamWriter osw = null;
create_file = openFileOutput("filename.txt", Context.MODE_WORLD_WRITEABLE);
osw = new OutputStreamWriter(create_file);
osw.write("text goes here");
osw.close();
create_file.close();
Run Code Online (Sandbox Code Playgroud)
我已在另一个活动中打开该文件,使用以下命令逐行读取内容:
FileInputStream open_file = openFileInput("filename.txt");
InputStreamReader isr = new InputStreamReader(open_file);
BufferedReader inRd = new BufferedReader(isr);
while ((getText = inRd.readLine()) != null)
{
Toast.makeText(getApplicationContext(), getText, Toast.LENGTH_SHORT).show();
}
Run Code Online (Sandbox Code Playgroud)
通过此操作,我已经验证了内容是否已存储,并确保该文件与内容一起存在,但是当我尝试使用以下方法从另一个活动覆盖该文件时:
FileOutputStream create_file = null;
OutputStreamWriter osw = null;
create_file = new FileOutputStream(new File(PasswordUtil.pswrd_file), false);
osw = new OutputStreamWriter(create_file);
osw.write(getString);
Run Code Online (Sandbox Code Playgroud)
我遇到一个例外,
java.io.FileNotFoundException:/ filename.txt (Read-only file system)
注意:文本文件存储在内部存储器中。
任何帮助,提前致谢。