我需要在加载Web内容时隐藏WebVew.我试着用这样的其他视图做到这一点:
<WebView
android:scrollbars="none"
android:id="@+id/id_webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<View
android:visibility="gone"
android:scrollbars="none"
android:id="@+id/id_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
Run Code Online (Sandbox Code Playgroud)
当我想隐藏WebView时,我将View的可见性更改为"visible"(View.setVisibility(View.VISIBLE);).但View不包含WebView,也没有隐藏.我需要在加载WebView时将视图放在前面.
如何从手机记忆中引用资产?我需要它将绝对路径写入html文件以加载一些资产文件夹中的图像.这个html保存在手机内存中,但是我无法将这些图像保存在内存手机中,因为它们非常大.
我需要将日期格式更改为UTC格式.
文件file = new File();
...
file.lastModified();
我需要以UTC格式转换文件的lastModified日期.
我想做一个HorizontalScrollView分页.如果您将屏幕向右移动,那么它将显示正确的"页面",如果您将屏幕向左移动,则它将显示左侧的"页面".
我已经实现了这个广播接收器:
public class ServiceManager extends BroadcastReceiver {
private final String BOOT_ACTION = "android.intent.action.BOOT_COMPLETED";
private final String BOOT_ACTION_FIRST_LAUNCH = "android.intent.action.PACKAGE_FIRST_LAUNCH";
private final String BOOT_ACTION_RESTARTED = "android.intent.action.PACKAGE_RESTARTED";
@Override
public void onReceive(Context context, Intent intent) {
// All registered broadcasts are received by this
String action = intent.getAction();
if (action.equalsIgnoreCase(BOOT_ACTION) || action.equalsIgnoreCase(BOOT_ACTION_FIRST_LAUNCH) ||
action.equalsIgnoreCase(BOOT_ACTION_RESTARTED)) {
// TODO: Action
}
}
}
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml中
<receiver android:name="package.service.ServiceManager" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.PACKAGE_FIRST_LAUNCH" />
<action android:name="android.intent.action.PACKAGE_RESTARTED" />
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
BOOT_COMPLETED操作正常,但是,PACKAGE_FIRST_LAUNCH和PACKAGE_RESTARTED无法正常工作.我需要在启动应用程序时启动广播接收器,这就是我使用这些操作的原因.但是,当我启动或重新启动应用程序时,接收器无法正常工作.它只在我重新启动手机时才有效.我的来源有什么问题吗?
我正在开发一个通用的Android应用程序,我需要检查应用程序是在平板电脑还是在手机中运行.有没有办法做到这一点?
我已经实现了一个调用服务的AlarmManager.问题是虽然我在AsyncTask中启动它,但它阻止了主线程.这是我的AsyncTask的来源:
private class NotificationsServiceTask extends AsyncTask<Void, Void, Void> {
private AlarmManager alarmMgr;
private PendingIntent pi;
@Override
protected Void doInBackground(Void... params) {
alarmMgr = (AlarmManager) LoginActivity.this.getSystemService(Context.ALARM_SERVICE);
Intent serviceIntent = new Intent(LoginActivity.this, Service.class);
pi = PendingIntent.getService(LoginActivity.this, 0, serviceIntent, 0);
alarmMgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), 120000, pi);
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
}
}
Run Code Online (Sandbox Code Playgroud)
我需要异步执行它,因为它阻塞了我的主线程.