我正在开发一个应用程序中的webView,其中当按下按钮时webview加载发生变化的内容(下一个和之前的两个按钮,它们只是更改webview中的内容).
如果我向下滚动到webview中的某个点并按下一个或上一个按钮,它将从同一点开始.我只是希望每次将新数据加载到webview时它都会显示从顶部开始的内容.我用过:
webView.scrollTo(0, 0);
Run Code Online (Sandbox Code Playgroud)
但是不起作用.它如何工作?请帮助任何人?
我有一些状态,我想在片段的生命周期中保存.例如,当屏幕旋转时,它工作正常,但是当从磁盘中杀死并恢复进程时(我认为它是如何工作的),我得到一个ClassCastException.这是一些代码:
初始化:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
playlistsMap = new LinkedHashMap<Section, List<Playlist>>();
} else {
playlistsMap = (LinkedHashMap<Section, List<Playlist>>) savedInstanceState.getSerializable(PLAYLISTS_MAP_KEY);
}
setHasOptionsMenu(true);
}
Run Code Online (Sandbox Code Playgroud)
保存数据:
@Override
public void onSaveInstanceState(Bundle outState) {
if (isEverySectionsLoaded()) {
outState.putSerializable(PLAYLISTS_MAP_KEY, playlistsMap);
} else {
outState.putSerializable(PLAYLISTS_MAP_KEY, new LinkedHashMap<Section, List<Playlist>>());
}
// ...
}
Run Code Online (Sandbox Code Playgroud)
我从演员阵容得到的例外onCreate:
04-10 01:06:43.430 E/AndroidRuntime(28549): FATAL EXCEPTION: main
04-10 01:06:43.430 E/AndroidRuntime(28549): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mydomain.android/com.mydomain.android.ui.MainActivity}:
java.lang.ClassCastException: java.util.HashMap cannot be cast to java.util.LinkedHashMap
Run Code Online (Sandbox Code Playgroud)
我知道在Android上使用parcelables会更好,但我仍然不明白这是怎么回事.
有任何想法吗?
我正在尝试将表情符号放在EditText中.我已经设法做到了它工作正常,但当我尝试使用软键盘从EditText删除这些表情符号时我遇到了问题.单击删除按钮,我无法执行此操作.当我插入一个新的ImageSpan时,我为它替换了imageId但是当我尝试删除de图标时,我必须删除所有imageId字符才能删除图像.
String fileName = "emoticon1.png";
Drawable d = new BitmapDrawable(getResources(), fileName);
String imageId = "[" + fileName + "]";
int cursorPosition = content.getSelectionStart();
int end = cursorPosition + imageId.length();
content.getText().insert(cursorPosition, imageId);
SpannableStringBuilder ss = new SpannableStringBuilder(content.getText());
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
ss.setSpan(span, cursorPosition, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
content.setText(ss, TextView.BufferType.SPANNABLE);
content.setSelection(end);
Run Code Online (Sandbox Code Playgroud)
我需要通过单击删除按钮来删除表情符号.请问你能帮帮我吗?
谢谢!
我正在使用Google Play服务中的PlacePicker库来启动新活动.新活动/选择器有一个工具栏(操作栏),默认情况下没有设置样式.
PlacePicker文档说明了这一点
如果使用材质主题在应用程序中设置自定义颜色,则场所选择器将从主题继承colorPrimary和colorPrimaryDark属性.
我的style.xml文件中有一个主题:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#5665bb</item>
<item name="android:colorPrimary">#5665bb</item>
<item name="colorPrimaryDark">#41456b</item>
<item name="android:colorPrimaryDark">#41456b</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我已经设置了在Android Manifesto文件中使用的主题
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
Run Code Online (Sandbox Code Playgroud)
placepicker由以下代码创建:
try {
PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder();
Intent intent = intentBuilder.build(Main.this);
// Start the intent by requesting a result,
// identified by a request code.
startActivityForResult(intent, REQUEST_PLACE_PICKER);
} catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
Log.e("", "Error with Google Play lib.");
}
Run Code Online (Sandbox Code Playgroud)
但是,工具栏不会设置样式.和以前一样,它有白色背景和黑色文字.有趣的是,我自己的工具栏(动作栏)确实得到了样式.
如何强制使用placepicker活动来采用我的主题?
android android-theme google-places-api google-play-services
我正在创建一个过渡.单击按钮时,将执行以下方法.该方法改变了图像视图的大小,位置,并将其淡化.我正在用它TransitionManager.beginDelayedTransition(); is too fast.来减缓过渡..但它仍然太快了.我该怎么做才能减缓过渡期.谢谢.
private void moveIcon() {
View moveableIcon = findViewById(R.id.moveableImageView);
TransitionManager.beginDelayedTransition(myLayout);
// change the position of the icon
RelativeLayout.LayoutParams positionRule = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT ,
RelativeLayout.LayoutParams.WRAP_CONTENT);
positionRule.addRule(RelativeLayout.ALIGN_PARENT_TOP , RelativeLayout.TRUE);
positionRule.addRule(RelativeLayout.ALIGN_PARENT_LEFT , RelativeLayout.TRUE);
moveableIcon.setLayoutParams(positionRule);
// change the size of the button
ViewGroup.LayoutParams sizeRules = moveableIcon.getLayoutParams();
sizeRules.width = 50;
sizeRules.height = 50;
moveableIcon.setLayoutParams(sizeRules);
fadeOutAndHideImage(image);
}
private void fadeOutAndHideImage(final ImageView img)
{
Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setInterpolator(new AccelerateInterpolator());
fadeOut.setDuration(1000);
fadeOut.setAnimationListener(new Animation.AnimationListener()
{
public void onAnimationEnd(Animation animation)
{ …Run Code Online (Sandbox Code Playgroud) 我试图以用户区域设置格式显示项目的价格,以与数据一起给出的相对货币.
例如,该项目为欧元,英国应显示为€123.64,但在法国应显示为123,64€
我希望根据用户区域设置放置货币符号和小数点分隔符.
然而,让我陷入困境的那件作品是如果物品没有便士/美分值的话就剥离.00.
我试过用
NumberFormat f = NumberFormat.getInstance(loc);
if (f instanceof DecimalFormat) {
((DecimalFormat)f).setDecimalSeparatorAlwaysShown(false);
}
Run Code Online (Sandbox Code Playgroud)
来自DecimalFormat.html#setCurrency
但它没有货币符号,即使我尝试f.setCurrency().
我也尝试将getInstance更改为getCurrencyInstance,现在应用货币符号,但忽略setDecimalSeparatorAlwaysShown(false)部分.
我已经考虑过检查剩余部分是否为0,然后将其剥离,但这需要我检查/知道小数分隔符是什么,虽然可能是可行的但是非常hacky.
有谁知道做所有这些事情的方法?!
我觉得这应该是微不足道的,但我似乎无法在手机屏幕上显示通知 - 它只显示在顶部的状态栏中.
有关我想要做的一个例子,这里是Facebook Messenger在收到消息时在屏幕上显示的方式.

每当我发送通知时,它所做的就是在状态栏中显示小图标 - 即使我将优先级设置为PRIORITY_MAX.我需要做另一个设置才能让它显示在屏幕上而不仅仅是状态栏吗?
通知显示代码:
PendingIntent contentIntent = PendingIntent.getActivity(context, nextId++, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Notification.Builder builder = new Notification.Builder(context)
.setContentTitle(title)
.setContentText(description)
.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.ic_stat_notification)
.setLargeIcon(largeIcon)
.setPriority(Notification.PRIORITY_DEFAULT)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL);
if (android.os.Build.VERSION.SDK_INT >= 21) {
builder.setColor(context.getResources().getColor(R.color.orange_500))
.setVisibility(Notification.VISIBILITY_PUBLIC);
}
Notification notification = builder.build();
notificationManager.notify(id, notification);
Run Code Online (Sandbox Code Playgroud) 我想创建可扩展的GridView,其行为类似于Google图像页面.我想知道如何实现这样的功能:当我点击其中一个图像时,页面会展开并显示图片的详细信息.是否有可能在Android中做类似的事情?
图像网格:

扩展图像网格:

我正在使用Retrofit来实现Rest Client,在尝试将响应体转换为模型Object时遇到了一些麻烦.
我的界面中有以下内容:
@POST("/users")
void createUser(@Body RegisterUserToken token, Callback<User> callback);
Run Code Online (Sandbox Code Playgroud)
我的User课基本上是一个POJO:
public class User {
private int id;
private String username;
private String email;
private String language;
// getters and setters...
}
Run Code Online (Sandbox Code Playgroud)
这就是我使用Rest Client的方式:
restClient.createUser(token, new Callback<User>() {
@Override
public void success(User user, Response response) {
// ...problem is here, with the user object
}
@Override
public void failure(RetrofitError error) {
// ...
}
});
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是响应主体没有被转换为User对象.我很确定问题是服务器正在返回:
{"user":{"id":13,"username":"john","email":"john@gmail.com","language":"eng"}}
Run Code Online (Sandbox Code Playgroud)
而不仅仅是:
{"id":13,"username":"john","email":"john@gmail.com","language":"eng"}
Run Code Online (Sandbox Code Playgroud)
鉴于我无法真正修改服务器代码,我如何自定义Retrofit/GSON以正确地将此响应主体转换为我的User对象?
我正在使用Retrofit从REST API获取书签:
public interface BookmarkService {
@GET("/bookmarks")
Observable<List<Bookmark>> bookmarks();
}
Run Code Online (Sandbox Code Playgroud)
现在我想延迟发出此列表中的每个项目.
我做了类似的东西这在Java中,但onCompleted永远不会触发.
private Observable<Bookmark> getBookmarks() {
return getBookmarkService().bookmarks()
.flatMap(new Func1<List<Bookmark>, Observable<Bookmark>>() {
@Override
public Observable<Bookmark> call(List<Bookmark> bookmarks) {
Observable<Bookmark> resultObservable = Observable.never();
for (int i = 0; i < bookmarks.size(); i++) {
List<Bookmark> chunk = bookmarks.subList(i, (i + 1));
resultObservable = resultObservable.mergeWith(Observable.from(chunk).delay(1000 * i, TimeUnit.MILLISECONDS));
}
return resultObservable;
}
})
.observeOn(AndroidSchedulers.mainThread());
}
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
用法:
mSwipeRefreshLayout.setRefreshing(true);
getBookmarks()
.subscribe(new Observer<Bookmark>() {
@Override
public void onCompleted() {
Timber.i("Completed");
mSwipeRefreshLayout.setRefreshing(false); …Run Code Online (Sandbox Code Playgroud) android ×10
java ×2
retrofit ×2
animation ×1
bundle ×1
currency ×1
galaxy-nexus ×1
rx-android ×1
rx-java ×1
scroll ×1
transitions ×1
webview ×1