如何在片段中获取上下文?
我需要用我的数据库其构造函数采用的背景下,但getApplicationContext()并FragmentClass.this没有工作,所以我能做些什么?
数据库构造函数
public Database(Context ctx)
{
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}
Run Code Online (Sandbox Code Playgroud) 如何在Android布局文件中定义带下划线的文本xml?
我不明白如何使用这个属性.谁能告诉我更多关于它的事情?
我正在尝试在Android中创建邮件发送应用程序.
如果我使用:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
Run Code Online (Sandbox Code Playgroud)
这将启动内置的Android应用程序; 我正在尝试直接发送邮件,而不使用此应用程序.
我有一个AsyncTask应该检查网络访问主机名.但是doInBackground()永远不会超时.有人有线索吗?
public class HostAvailabilityTask extends AsyncTask<String, Void, Boolean> {
private Main main;
public HostAvailabilityTask(Main main) {
this.main = main;
}
protected Boolean doInBackground(String... params) {
Main.Log("doInBackground() isHostAvailable():"+params[0]);
try {
return InetAddress.getByName(params[0]).isReachable(30);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
protected void onPostExecute(Boolean... result) {
Main.Log("onPostExecute()");
if(result[0] == false) {
main.setContentView(R.layout.splash);
return;
}
main.continueAfterHostCheck();
}
}
Run Code Online (Sandbox Code Playgroud) 特别是,我在哪里可以浏览任何Android源应用程序(例如联系人应用程序)的源代码?是下载所有的唯一方法吗?
我在使用Android的XML中找到形状定义的文档时遇到了一些问题.我想在XML文件中定义一个填充纯色的简单圆圈,以将其包含在我的布局文件中.
可悲的是,android.com上的文档没有涵盖Shape类的XML属性.我想我应该使用ArcShape来绘制圆形,但是没有解释如何设置圆形从圆弧中所需的大小,颜色或角度.
这是我的布局代码;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:text="@string/welcome"
android:id="@+id/TextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView>
<LinearLayout android:id="@+id/LinearLayout"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom">
<EditText android:id="@+id/EditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</EditText>
<Button android:text="@string/label_submit_button"
android:id="@+id/Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这看起来像在左边,我希望它看起来像在右边.

显而易见的答案是在高度上将TextView设置为fill_parent,但这不会为按钮或输入字段留下任何余地.本质上问题是我希望提交按钮和文本条目在底部是固定高度,文本视图填充剩余的空间,类似于水平线性布局我希望提交按钮包装其内容和用于填充剩余空间的文本条目.
如果线性布局中的第一个项目被告知fill_parent它就是这样做的,没有其他项目的空间,我如何获得一个线性布局中的第一个项目来填充除了其余项目所需的最小空间之外的所有空间布局中的项目?
编辑:
相对布局确实是答案 - 谢谢!
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="@string/welcome"
android:id="@+id/TextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
</TextView>
<RelativeLayout
android:id="@+id/InnerRelativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:text="@string/label_submit_button"
android:id="@+id/Button"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
<EditText
android:id="@+id/EditText"
android:layout_width="fill_parent"
android:layout_toLeftOf="@id/Button"
android:layout_height="wrap_content">
</EditText>
</RelativeLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 如何在没有拖放支持的Genymotion模拟器中安装Google Play服务?
我不能像Stack Overflow post中提到的那样安装它如何在Genymotion虚拟设备上安装Google框架(Play,Accounts等)?由于缺乏对拖放安装的支持.
Genymotion支持几个模拟器的Google Apps,但它不支持平板电脑模拟器.
如何以ImageView编程方式设置宽度和高度?
android ×10
java ×2
asynchronous ×1
email ×1
fonts ×1
genymotion ×1
jakarta-mail ×1
networking ×1
shapes ×1
xml ×1