在我的应用程序中,我有一个折叠工具栏.如果我启动一个特定的片段,我想要折叠工具栏,使其表现得像一个"正常",并且用户不能自己花费它.这是我用于工具栏的布局:
<android.support.design.widget.AppBarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:titleEnabled="false"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:src="@drawable/drawer_background"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
android:layout_width="match_parent"
android:layout_height="172dp"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
android:minHeight="100dp" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)
我也可以从代码中折叠布局,如下所示:
appBarLayout.setExpanded(false, false);
final AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
params.setScrollFlags(0);
collapsingToolbarLayout.setLayoutParams(params);
Run Code Online (Sandbox Code Playgroud)
但这没有用.如果用户从工具栏向下滑动,它将展开.
你有什么想法吗?
我有两个设备.一个是HTC WildFire S,另一个是HTC 1V.我Geocoder.getFromLocationName()
在我的应用程序中使用了它.它在HTC野火S中成功运行.但在HTC 1V我得到以下错误.为什么会来?我怎么解决这个问题?请任何人帮助我.
码
Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());
//s is the address
List<Address> addresses = geoCoder.getFromLocationName(s, 5); //Here i got the following Exception.
Run Code Online (Sandbox Code Playgroud)
错误
06-18 16:28:17.933: W/System.err(4960): java.io.IOException: Service not Available
06-18 16:28:17.953: W/System.err(4960):at android.location.Geocoder.getFromLocationName(Geocoder.java:178)
Run Code Online (Sandbox Code Playgroud)
位置标签
创建了一个循环进度条,它与动画一起正常工作.但在尝试使用动态数据显示它时,进度条不会更新.
下面的代码工作正常
progrssBarObj = FindViewById<ProgressBar>(Resource.Id.progressBarSync);
ObjectAnimator animation = ObjectAnimator.OfInt(progrssBarObj, "progress", 0, 100); // see this max value coming back here, we animale towards that value
animation.SetDuration(3000); //in milliseconds
animation.SetInterpolator(new DecelerateInterpolator());
animation.Start();
Run Code Online (Sandbox Code Playgroud)
和AXML代码是
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_column="2"
android:id="@+id/progressBarSync"
android:layout_width="300dp"
android:layout_height="300dp"
android:progressDrawable="@drawable/circular_progress_bar"
android:background="@drawable/progress_bar_background" />
Run Code Online (Sandbox Code Playgroud)
但是当我在循环中尝试类似的东西时,进度条没有更新数据.基本上进度条没有在圆圈中更新.
for (int i = 0; i <= 100; i++)
{
int cnt = 0;
cnt = cnt + i;
progrssBarObj.Progress = cnt;
}
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
在获取当前位置流时,我正在使用SettingsClient根据当前LocationRequest来检查是否满足位置设置。目前,我的优先级设置为HIGH_ACCURACY,这需要不惜一切代价启用GPS。
fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
settingsClient = LocationServices.getSettingsClient(this);
locationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setInterval(500)
.setFastestInterval(500);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
builder.addLocationRequest(locationRequest);
locationSettingsRequest = builder.build();
Run Code Online (Sandbox Code Playgroud)
现在,当我调用给它提供侦听器的SettingsClient.checkLocationSettings()时,
settingsClient.checkLocationSettings(locationSettingsRequest)
.addOnCompleteListener(this)
.addOnFailureListener(this);
Run Code Online (Sandbox Code Playgroud)
它属于onFailure(),在这种情况下,github上的google官方示例采用以下方法;
检查在onFailure()中接收到的异常的状态码(如果它是LocationSettingsStatusCodes.RESOLUTION_REQUIRED),然后调用startResolutionForResult(),它允许我们启用GPS,这将等待使用onActivityResult的结果。
@Override
public void onFailure(@NonNull Exception e) {
int statusCode = ((ApiException) e).getStatusCode();
switch (statusCode) {
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
try {
// Show the dialog by calling startResolutionForResult(), and check the
// result in onActivityResult().
ResolvableApiException rae = (ResolvableApiException) e;
rae.startResolutionForResult(LocationActivity.this, REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException sie) {
showLocationError();
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE: …
Run Code Online (Sandbox Code Playgroud) 像UIView这样的特殊类有多个指定的初始化程序.
在Objective-X中,我们可以将常见初始化分解为单独的函数
- (id)initWithCoder:(NSCoder *)aDecoder {
if (self = [super initWithCoder:aDecoder]) {
[self initialize];
}
return self;
}
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self initialize];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
在Swift中,这不再是一种可能性,因为以下代码会导致"在super.init调用之前自行使用"
override init(frame: CGRect) {
self.initialize()
super.init(frame: frame)
}
required init(coder aDecoder: NSCoder) {
self.initialize()
super.init(coder: aDecoder)
}
Run Code Online (Sandbox Code Playgroud)
在super.init之后放置self.initialize也没有帮助,因为我的整个目的是初始化成员.以下将导致'属性self.X未在super.init调用时初始化'
var X : Int
override init(frame: CGRect) {
super.init(frame: frame)
self.initialize()
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.initialize()
}
Run Code Online (Sandbox Code Playgroud)
如果我想在这种情况下考虑常见的初始化,我该怎么办?请注意,我特别不想使用awakeFromNib,因为我希望我的对象在我的对象层次结构中的任何相关awakeFromNib实现中可用.另请注意,选项对我的用例没有意义.
Location
从服务发送到自定义BroadcastReceiver时遇到问题.
这是我的BroadcastReceiver.cs
[BroadcastReceiver]
class MyBroadcastReceiver : BroadcastReceiver
{
public static readonly string GRID_STARTED = "GRID_STARTED";
public event EventHandler<OnLocationChangedEventArgs> mOnLocationChanged;
private Location location;
public override void OnReceive(Context context, Intent intent)
{
if (intent.Action == GRID_STARTED)
{
Toast.MakeText(context, "Grid Started", ToastLength.Short).Show();
//location = JsonConvert.DeserializeObject<Location>(intent.GetStringExtra("location"));
//mOnLocationChanged.Invoke(this, new OnLocationChangedEventArgs(location));
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果我在上面的代码中取消两行,我的应用程序突然停止.我无法告诉你错误是什么,因为在开发Xamarin应用程序时,调试是由内部错误停止的(我在Xamarin论坛上读过它但是没时间处理它).
这就是我在服务中所做的:
private void BroadcastStarted(Location location)
{
Intent BroadcastIntent = new Intent(this, typeof(MyBroadcastReceiver));
BroadcastIntent.PutExtra("location",JsonConvert.SerializeObject(location));
BroadcastIntent.SetAction(MyBroadcastReceiver.GRID_STARTED);
BroadcastIntent.AddCategory(Intent.CategoryDefault);
SendBroadcast(BroadcastIntent);
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Newtonsoft.Json发送一个对象.任何帮助,将不胜感激.
更新:
好吧,不知怎的,我设法揭示错误:
无法找到用于Android.Location.Location类型的构造函数.一个类应该有一个默认的构造函数,一个带参数的构造函数或一个用JsonConstructor属性标记的构造函数.
更新:
整个服务代码:
using Newtonsoft.Json;
namespace GoogleMaps
{ …
Run Code Online (Sandbox Code Playgroud) 我的应用没有个人用户,而是有一些由客户端生成并可以被其他人看到的数据,例如公共聊天频道,用户名也是临时的。
我不需要对每个用户帐户数据进行身份验证。而是仅在请求来自我的应用程序的情况下才应提供,否则应不会提供。我看到有用户身份验证,但这意味着我必须跟踪uids等,这也增加了数据存储,另一个选择是,如果我删除auth(将读/写设置为public)并从应用程序中调用数据更改。
我可以在Android应用中使用服务器使用的应用机密功能吗?这是服务器的规则:
{
"rules": {
".read": true,
".write": "auth.uid = 'myserver'"
}
}
Run Code Online (Sandbox Code Playgroud)
如何使其适用于我的Android应用程序?
当只有我知道url并且只有我的程序包是通过服务器上的android app选项配置的时,如果没有身份验证(设置读/写公共),我的应用程序怎么会不安全?
除了用户身份验证之外,还有什么方法可以确保数据安全?
即使在从Xamarin Component Store安装v4支持库后,我也会收到此错误.我尝试使用Google搜索这些问题,但在开发Android应用时,我总是在Xamarin Studio中遇到同样的错误