如何更改地图的"地点自动完成"搜索的字体系列?



我想将字体更改为我的字体目录中的nunito_sans.xml。我已经将放置自动完成搜索包装成线性布局以获得我想要的背景颜色 - 希望这不会引起问题。此外,输入字符后,字体更改需要扩展到搜索框下方显示的列表。

活动代码:

public class ExploreFragment extends Fragment implements OnMapReadyCallback {
GoogleMap mapView;
private Location currentLocation;
private FusedLocationProviderClient fusedLocationProviderClient;
private static final int REQUEST_CODE = 101;
private DatabaseReference mosqueDatabase;
private String apiKey = "MY_API_KEY";
private PlacesClient placesClient;
LatLng userLocation;
FloatingActionButton buttonCurrentLocation;
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_explore, null, false);
mosqueDatabase = FirebaseDatabase.getInstance().getReference("Timetable");
fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(getContext());
lastLocation();
buttonCurrentLocation = view.findViewById(R.id.buttonCurrentLocation);
buttonCurrentLocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mapView.animateCamera(CameraUpdateFactory.newLatLng(userLocation));
}
});
if (!Places.isInitialized()) {
Places.initialize(getContext(), apiKey);
}
placesClient = Places.createClient(getContext());
final AutocompleteSupportFragment autocompleteSupportFragment = (AutocompleteSupportFragment) getChildFragmentManager()
.findFragmentById(R.id.fragmentAutocomplete);
autocompleteSupportFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.LAT_LNG, Place.Field.NAME));
autocompleteSupportFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(@NonNull Place place) {
final LatLng searchLocation = place.getLatLng();
mapView.animateCamera(CameraUpdateFactory.newLatLng(searchLocation));
}
@Override
public void onError(@NonNull Status status) {
}
});
return view;
}
@Override
public void onMapReady(GoogleMap googleMap) {
mapView = googleMap;
userLocation = new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude());
mapView.animateCamera(CameraUpdateFactory.newLatLngZoom(userLocation, 15.0f));
mosqueDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot: dataSnapshot.getChildren()) {
String schoolApproved = snapshot.child("Approved").getValue(String.class);
if (schoolApproved.equals("Yes")) {
String stringSchool = snapshot.child("Name").getValue(String.class);
Double doubleLatitude = snapshot.child("Latitude").getValue(Double.class);
Double doubleLongitude = snapshot.child("Longitude").getValue(Double.class);
LatLng schoolLocation = new LatLng(doubleLatitude, doubleLongitude);
mapView.addMarker(new MarkerOptions().position(schoolLocation).title(stringSchool));
//mapView.animateCamera(CameraUpdateFactory.newLatLngZoom(schoolLocation, 15.0f));
}
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case REQUEST_CODE:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
lastLocation();
}
break;
}
}
private void lastLocation() {
if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(getActivity(), new String[]
{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_CODE);
}
Task<Location> task = fusedLocationProviderClient.getLastLocation();
task.addOnSuccessListener(new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
if (location != null) {
currentLocation = location;
SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager()
.findFragmentById(R.id.mapView);
mapFragment.getMapAsync(ExploreFragment.this);
}
}
});
}
}

XML代码:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/mapView"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginLeft="6dp"
android:layout_marginTop="6dp"
android:layout_marginRight="6dp"
android:background="@drawable/map_search_outline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<fragment
android:id="@+id/fragmentAutocomplete"
android:name="com.google.android.libraries.places.widget.AutocompleteSupportFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/buttonCurrentLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginBottom="64dp"
android:backgroundTint="#D9FFFFFF"
android:clickable="true"
android:tint="#4A89F3"
app:borderWidth="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/gps" />
</androidx.constraintlayout.widget.ConstraintLayout>

先看看这个问题 如何在安卓中自动完成片段的位置更改文本大小?

Typeface face = Typeface.createFromAsset(getAssets(),
"fonts/epimodem.ttf");
((EditText)placeAutocompleteFragment.getView().findViewById(R.id.place_autocomplete_search_input)).setTypeface(face);

相关内容

  • 没有找到相关文章

最新更新