当我的活动ScrollView布局和EditTexts开始时,EditTexts得到焦点并且Android OnScreen键盘打开.
我怎么能避免这种情况?
当我使用LinearLayout和RelativeLayout没有ScrollView它时,它不会发生.
我已经尝试过这种方式了,但它确实有效,但这不是一个好方法:
TextView TextFocus = (TextView) findViewById(R.id.MovileLabel);
TextFocus.setFocusableInTouchMode(true);
TextFocus.requestFocus();
Run Code Online (Sandbox Code Playgroud)
接下来你有一些我的布局有这个问题的例子,当这个Activity开始时,焦点转到第一个EditText,描述和Android键盘自动打开,这非常烦人.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10px">
<RelativeLayout
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/UserLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="13px"
android:text="@string/userlabel"/>
<TextView
android:id="@+id/User"
android:layout_alignBaseline="@id/UserLabel"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test"/>
</RelativeLayout>
<View
android:layout_gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#808080"
android:layout_marginTop="5px"
android:layout_marginBottom="12px"/>
<RelativeLayout
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/DescriptionLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/desclabel"
android:layout_marginTop="13px"/>
<EditText
android:id="@+id/Description"
android:layout_alignBaseline="@id/DescriptionLabel" …Run Code Online (Sandbox Code Playgroud) 我有一个命令行apk生成器,使用相同的源代码编译很多APK,所以这些应用程序具有相同的依赖项.
在gradle文档中,我可以看到:
Gradle项目需要网络连接才能下载依赖项.
我知道可以将gradle配置为脱机工作,而不是下载为其他apks下载的相同依赖项.如何激活此离线模式?
android gradle android-build android-studio android-gradle-plugin
我需要从资产加载图像,以避免在某些特定情况下调整POT图像的froyo 2.2.2错误.避免它的方法是从资源目录加载图像文件.
我正试着这样做:
String imagePath = "radiocd5.png";
AssetManager mngr = context.getAssets();
// Create an input stream to read from the asset folder
InputStream is=null;
try {
is = mngr.open(imagePath);
} catch (IOException e1) { e1.printStackTrace();}
//Get the texture from the Android resource directory
//InputStream is = context.getResources().openRawResource(R.drawable.radiocd5);
Bitmap bitmap = null;
try {
//BitmapFactory is an Android graphics utility for images
bitmap = BitmapFactory.decodeStream(is);
} finally {
//Always clear and close
try {
is.close();
is = null;
} catch (IOException …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用SHARE INTENTAndroid从Facebook,Twitter等分享图像.
我找到了将图像发送到共享意图的代码,但是这段代码需要位图的URI: fullSizeImageUri
这是完整的代码:
private void startShareMediaActivity(Bitmap image) {
boolean isVideo=false;
String mimeType="bmp";
Uri fullSizeImageUri=null;
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType(mimeType);
intent.putExtra(Intent.EXTRA_STREAM, fullSizeImageUri);
try {
startActivity(Intent.createChooser(intent, (isVideo ? "video" : "image")));
} catch (android.content.ActivityNotFoundException ex) { }
}
Run Code Online (Sandbox Code Playgroud)
请问有人可以帮我将Bitmap转换为Uri吗?
谢谢
我有一些我希望从服务访问的共享首选项(纬度,经度),它不是来自Activity的子类.
特别是,当我尝试访问getPreferences时,此功能在服务上不存在.我的代码发布在下面
我的目标是允许在我的服务中使用这些共享首选项.有什么建议/例子可以帮助我吗?
public class MyService extends Service implements Runnable {
LocationManager mLocationManager;
Location mLocation;
MyLocationListener mLocationListener;
Location currentLocation = null;
static SharedPreferences settings;
static SharedPreferences.Editor configEditor;
public IBinder onBind(Intent intent) {
return null;
}
public void onCreate() {
settings = this.getPreferences(MODE_WORLD_WRITEABLE);
configEditor = settings.edit();
writeSignalGPS();
}
private void setCurrentLocation(Location loc) {
currentLocation = loc;
}
private void writeSignalGPS() {
Thread thread = new Thread(this);
thread.start();
}
@Override
public void run() {
mLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Looper.prepare();
mLocationListener …Run Code Online (Sandbox Code Playgroud) 其实我知道如何打开PNG文件作为位图.但我的代码不适用于打开的JPG文件,我不知道为什么.
我无法在SO或谷歌上找到关于如何执行此操作的正确示例.
我需要有一个位图,其中包含从SD卡的目录打开的JPG文件.例如"sdcard/images/01.jpg"
谢谢
我想在应用程序运行时在状态栏中放置一个图标,包括它在后台运行时.我怎样才能做到这一点?
现在,你可以把versionCode和versionName两个build.gradle和AndroidManifest.xml文件.哪个是放置这些属性的最佳位置,为什么它比其他选项更好?
我在谷歌官方文档中找不到任何关于此的信息:
https://developer.android.com/tools/building/configuring-gradle.html
http://developer.android.com/guide/topics/manifest/manifest-element.html
非常感谢.
android gradle android-manifest build.gradle android-gradle-plugin
我在我的Android APP上有一个后台服务,它正在获取我的GPS位置并将其发送到远程数据库.它工作得很好.
问题是当我想要停止服务......它不会停止:S.也没有出现logcat上的异常或错误......它根本不会停止.
这是启动我的srvice的代码(带按钮):
startService(new Intent(GPSLoc.this, MyService.class)); //enciendo el service
Run Code Online (Sandbox Code Playgroud)
这是我停止它的代码(在onactivityresult方法上):
stopService(new Intent(GPSLoc.this, MyService.class));
Run Code Online (Sandbox Code Playgroud)
我已经调试了应用程序,并且我检查了每次调试它时都调用了stopService代码行,但它没有停止......
我确信它没有停止导致我的数据库,当我按下按钮停止服务时,我仍然从模拟器中恢复gps位置.
我做得不好?
我喜欢分享意图,非常适合用图像和文本参数打开共享应用程序.
但现在我正在研究如何强制分享意图从列表中打开一个特定的应用程序,并给出共享意图的参数.
这是我的实际代码,它显示了手机上安装的共享应用列表.请问,有人可以告诉我应该添加什么代码以强制举例如官方Twitter应用程序?和官方的faccebok应用程序?
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse("file:///sdcard/test.jpg");
sharingIntent.setType("image/*");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "body text");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
Run Code Online (Sandbox Code Playgroud)
谢谢