在VideoView中播放视频时,Android后退按钮无效.但它在播放视频之前有效.我正在为VideoView使用自定义MediaController.
我尝试使用dispatchKeyEvent,它无法正常工作.
使用VideoView的活动代码:
mc = new CustomMediaController(mVideo.getContext(), screenIcon) {
@Override
public void hide(){
}
@Override
public boolean dispatchKeyEvent(KeyEvent event){
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
super.hide();
((Activity) getContext()).finish();
return true;
}
return super.dispatchKeyEvent(event);
}
};
Run Code Online (Sandbox Code Playgroud)
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
onBackPressed();
finish();
}
return true;
}
@Override
public void onBackPressed() {
super.onBackPressed();
finish();
}
Run Code Online (Sandbox Code Playgroud)
CustomMediaController还包含dispatchKeyEvent:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
((Activity) getContext()).finish();
}
return super.dispatchKeyEvent(event); …Run Code Online (Sandbox Code Playgroud) 我在堆栈溢出中发现了这个问题,但没有适当的解决方案.
通过滚动隐藏后以编程方式显示工具栏(Android设计库)
我在工具栏中有一个自定义视图,当我向上和向下滚动时,工具栏将显示和隐藏.
当我向上滚动时,工具栏将隐藏,我在ActionBar菜单中显示一个图标.当我点击该菜单时,我想显示隐藏的工具栏,其内容具有相同的动画.
我试着翻译工具栏但没用.
这是我的自定义视图工具栏代码.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginRight="15dp"
android:background="@drawable/searchbox_bg"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="2">
<EditText
android:layout_width="fill_parent"
android:layout_height="40dp"
android:hint="@string/home_search_hint"
android:maxLines="1"
android:textSize="15dp"
android:singleLine="true"
android:id="@+id/home_search"
android:drawableStart="@android:drawable/ic_menu_search"
android:drawableLeft="@android:drawable/ic_menu_search"
android:drawablePadding="3dp"
android:drawableTint="@color/gray_2"
android:drawingCacheQuality="high"
android:paddingLeft="10dp"
android:background="@drawable/searchbox_bg"
android:layout_weight="2"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="2"
android:id="@+id/home_speak"
android:background="@drawable/searchbox_bg"
android:src="@android:drawable/ic_btn_speak_now"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/transparent"
android:visibility="invisible"/>
</android.support.design.widget.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)
android android-toolbar android-recyclerview android-coordinatorlayout android-appbarlayout
在Google Places API for Android中,我使用PlaceAutocompleteFragment来显示城市/国家/地区.
这里得到的地址,名称,placeId等
Place对象只包含这些字段.
@Override
public void onPlaceSelected(Place place) {
Log.i(TAG, "Place Selected: " + place.getName());
// Format the returned place's details and display them in the TextView.
mPlaceDetailsText.setText(formatPlaceDetails(getResources(), place.getName(), place.getId(),
place.getAddress(), place.getPhoneNumber()+" "+place.getAttributions()+" :: "+place.getLocale(), place.getWebsiteUri()));
Run Code Online (Sandbox Code Playgroud)
}
但我也想要国家代码.有没有办法从地方API获取国家/地区代码?如果不是,在输入时是否有任何替代服务来获取国家/地区名称和代码?