Android 如何更改“自动完成”地图搜索的字体系列?

Android 如何更改“自动完成”地图搜索的字体系列?,android,google-maps,Android,Google Maps,我想将字体更改为nunito_sans.xml,它位于我的字体目录中。我已经将Place Autocomplete搜索包装在一个线性布局中,以获得我想要的背景颜色-希望这不会引起问题。此外,一旦输入字符,字体更改将需要扩展到搜索框下方的列表 活动代码: public class ExploreFragment extends Fragment implements OnMapReadyCallback { GoogleMap mapView; private Location

我想将字体更改为nunito_sans.xml,它位于我的字体目录中。我已经将Place Autocomplete搜索包装在一个线性布局中,以获得我想要的背景颜色-希望这不会引起问题。此外,一旦输入字符,字体更改将需要扩展到搜索框下方的列表

活动代码:

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);
                }
            }
        });
    }
}
public class exploreefragment扩展了mapreadycallback上的片段实现{
谷歌地图地图视图;
私人位置;
私有FusedLocationProviderClient FusedLocationProviderClient;
私有静态最终整数请求_代码=101;
私人数据库;参考数据库;
私有字符串apiKey=“我的API\U密钥”;
私人场所客户场所客户;
LatLng用户位置;
浮动操作按钮当前位置;
创建视图时的公共视图(@NonNull LayoutInflater充气机、视图组容器、最终捆绑包保存状态){
视图=充气机。充气(R.layout.fragment\u explore,null,false);
mosqueDatabase=FirebaseDatabase.getInstance().getReference(“时间表”);
fusedLocationProviderClient=LocationServices.getFusedLocationProviderClient(getContext());
lastLocation();
buttonCurrentLocation=view.findViewById(R.id.buttonCurrentLocation);
buttonCurrentLocation.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
animateCamera(CameraUpdateFactory.newLatLng(userLocation));
}
});
如果(!Places.isInitialized()){
初始化(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,Place.Field.NAME));
autocompleteSupportFragment.setOnPlaceSelectedListener(新的PlaceSelectionListener(){
@凌驾
已选择公共空位置(@NonNull Place){
最终LatLng搜索位置=place.getLatLng();
mapView.animateCamera(CameraUpdateFactory.newLatLng(searchLocation));
}
@凌驾
public void onError(@NonNull状态){
}
});
返回视图;
}
@凌驾
4月1日公开作废(谷歌地图谷歌地图){
mapView=谷歌地图;
userLocation=new LatLng(currentLocation.getLatitude(),currentLocation.getLength());
animateCamera(CameraUpdateFactory.newLatLngZoom(userLocation,15.0f));
mosqueDatabase.addListenerForSingleValueEvent(新的ValueEventListener()){
@凌驾
public void onDataChange(@NonNull DataSnapshot DataSnapshot){
对于(DataSnapshot快照:DataSnapshot.getChildren()){
String schoolApproved=snapshot.child(“Approved”).getValue(String.class);
如果(学校批准,等于“是”){
String stringSchool=snapshot.child(“Name”).getValue(String.class);
Double doubleLatitude=snapshot.child(“纬度”).getValue(Double.class);
Double doubleLongitude=snapshot.child(“经度”).getValue(Double.class);
LatLng学校位置=新LatLng(双纬度、双经度);
addMarker(新的MarkerOptions().position(schoolLocation).title(stringSchool));
//mapView.animateCamera(CameraUpdateFactory.newLatLngZoom(学校位置,15.0f));
}
}
}
@凌驾
已取消的公共void(@NonNull DatabaseError DatabaseError){
}
});
}
@凌驾
public void onRequestPermissionsResult(int-requestCode,@NonNull-String[]permissions,@NonNull-int[]grantResults){
开关(请求代码){
案例请求代码:
if(grantResults.length>0&&grantResults[0]==PackageManager.PERMISSION\u已授予){
lastLocation();
}
打破
}
}
私有void lastLocation(){
if(ActivityCompat.checkSelfPermission(getContext(),Manifest.permission.ACCESS\u FINE\u LOCATION)!=PackageManager.permission\u已授予){
ActivityCompat.requestPermissions(getActivity(),新字符串[]
{Manifest.permission.ACCESS\u FINE\u LOCATION},请求\u代码);
}
Task Task=fusedLocationProviderClient.getLastLocation();
task.addOnSuccessListener(新的OnSuccessListener(){
@凌驾
成功时的公共无效(位置){
如果(位置!=null){
当前位置=位置;
SupportMapFragment mapFragment=(SupportMapFragment)getChildFragmentManager()
.findFragmentById(R.id.mapView);
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>

先检查这个问题


我已从您的问题中删除了您的API密钥。请不要在公共站点上共享私有API密钥,并确保按照
Typeface face = Typeface.createFromAsset(getAssets(),
            "fonts/epimodem.ttf");
((EditText)placeAutocompleteFragment.getView().findViewById(R.id.place_autocomplete_search_input)).setTypeface(face);