小编max*_*xxo的帖子

在Swift中更改MKMapView上的图钉图像

我试图在Swift中改变MKMapView上的pin图像,但不幸的是它不起作用.任何想法我做错了什么?我在这里看到了一些例子,但没有奏效.

import UIKit
import MapKit

class AlarmMapViewController: UIViewController {
    @IBOutlet weak var map: MKMapView!

    override func viewDidLoad() {
        super.viewDidLoad()
        showAlarms()
        map.showsUserLocation = true
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    func showAlarms(){

        map.region.center.latitude = 49
        map.region.center.longitude = 12
        map.region.span.latitudeDelta = 1
        map.region.span.longitudeDelta = 1

        for alarm in Alarms.sharedInstance.alarms {

            let location = CLLocationCoordinate2D(
                latitude: Double(alarm.latitude),
                longitude: Double(alarm.longtitude)
            )

            let annotation = MKPointAnnotation()
            annotation.setCoordinate(location)
            annotation.title = alarm.name
            annotation.subtitle = alarm.description
            mapView(map, viewForAnnotation: annotation).annotation = annotation
            map.addAnnotation(annotation)
        }
    }

    @IBAction func zoomIn(sender: …
Run Code Online (Sandbox Code Playgroud)

ios swift

8
推荐指数
2
解决办法
1万
查看次数

cloding fragment 时如何使用导航架构组件隐藏键盘

我在一项活动中托管了几个片段。当某些片段关闭时,如果打开,则需要隐藏键盘,通常通过将 onOptionsItemSelected 从活动链接到片段来完成

override fun onOptionsItemSelected(item: MenuItem): Boolean {
    when (item.itemId) {
        android.R.id.home -> {
            UiUtil.hideKeyboard(activity)
            return true
        }

        else -> return super.onOptionsItemSelected(item)
    }
}
Run Code Online (Sandbox Code Playgroud)

但是当使用导航架构组件时,它看起来真的很糟糕。有什么简单的方法可以用导航架构组件隐藏键盘吗?

android android-fragments android-architecture-components

8
推荐指数
2
解决办法
1246
查看次数

android volley JsonObjectRequest,它只返回200个正文

如何在volley中发出JSON请求,我需要在body中发送一个authentification头和JSON对象,我希望只有一个状态代码200回答

JsonObjectRequest request = new JsonObjectRequest(
                method,
                url,
                myJsonObject,
                responseListener,
                errorListener) {

            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<String, String>();
                String creds = String.format("%s:%s", login, password);
                String auth = "Basic " + Base64.encodeToString(creds.getBytes(), Base64.DEFAULT);
                headers.put("Authorization", auth);
                return headers;
            }
        };


new Response.Listener<String>(){

                                @Override
                                public void onResponse(String response) {
                                    Toast.makeText(getActivity(), response, 1000).show();

                                }
Run Code Online (Sandbox Code Playgroud)

我尝试了使用字符串或JSON对象,对象的不同种类的响应侦听器,但始终存在错误:android volley org.json.JSONException:在字符0处输入的结尾

或者是否有任何其他类型的请求在volley中支持和json对象和authentification标头在正文和响应只是一个http状态代码?

android json android-volley

7
推荐指数
3
解决办法
5600
查看次数

恢复数据库文件后重新打开房间数据库

DB文件恢复后如何正确重新打开数据库?我在 AppModule 中打开它,如下所示:

@Singleton
@Provides
fun provideDb(app: Application): FastcountDb {
    val db: FastcountDb = Room.databaseBuilder(app, FastcountDb::class.java, AppConfig.DB_NAME + ".db")
            .fallbackToDestructiveMigration()
            .setJournalMode(RoomDatabase.JournalMode.TRUNCATE)
            .build()

    return db
}
Run Code Online (Sandbox Code Playgroud)

当我备份或恢复数据库文件时,我只需调用 RoomDatabase.close() 复制数据库文件,然后需要重新打开数据库。有什么方法可以再次触发provideDb(app:Application)吗?

android kotlin android-sqlite android-room

6
推荐指数
0
解决办法
360
查看次数

Android volley如何使用身份验证头和Json对象发送请求

我需要通过volley发送一个带有authentification头和Json对象的http请求.我没有在凌空中找到这个请求.

我找到了GsonRequest和JsonObjectRequest. GsonRequest int方法,String url,Class clazz,Map headers,Listener listener,ErrorListener errorListener,Gson useGson)

JsonObjectRequest (int方法,java.lang.String url,JSONObject jsonRequest,Response.Listener侦听器,Response.ErrorListener errorListener)

知道该怎么办?

android json android-volley

4
推荐指数
1
解决办法
2万
查看次数

在我的应用程序中使用NFC时如何禁用默认的Android NFC应用程序

在我的应用中,我正在使用NFC读取标签。我单击按钮以启用NFC。将打开一个进度对话框以读取NFC标记,完成后将禁用NFC。一切都很好。但是,当应用程序中未启用NFC且我在手机上放置了NFC标签时,默认的Android应用程序会读取NFC标签并将我的应用程序置于后台。

如何禁用Android应用程序?

我的启用/禁用NFC的代码:

/**
 * @param activity The corresponding {@link Activity} requesting the foreground dispatch.
 * @param adapter  The {@link NfcAdapter} used for the foreground dispatch.
 */
public static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) {
    final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);
    IntentFilter[] filters = new IntentFilter[1];
    String[][] techList = new String[][]{};

    // Notice that this is the same filter as in our manifest.
    filters[0] = new IntentFilter();
    filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
    filters[0].addCategory(Intent.CATEGORY_DEFAULT); …
Run Code Online (Sandbox Code Playgroud)

java android nfc

2
推荐指数
1
解决办法
5726
查看次数