0
* 현재 내비게이션 창을 사용하고 있습니다. 각 탭에 대한 웹보기가 있습니다. 페이지를로드하고 탐색 할 수는 있지만 되돌릴 수는 없습니다. 다시 앱을 닫습니다. 아래의 onbackpressed는 webview1 인 1 개의 webview에 대해서만 작동합니다 (그 뒤에는 작동합니다). 그러나 다른 webview는 앱을 닫았습니다. 당신의 버튼이 시도 onbackpressed *안드로이드 내비게이션 드로어에서 복수 웹 뷰용 백팩
public class MainActivity extends ActionBarActivity
implements NavigationDrawerFragment.NavigationDrawerCallbacks {
****@Override
public void onBackPressed() {
WebView webView1;
webView1 = (WebView) findViewById(R.id.webView1);
// If there is history in the web view, go back
if (webView1.canGoBack()) {
webView1.goBack();
return;
}
//Handle anything else
super.onBackPressed();
}****
/**
* Fragment managing the behaviors, interactions and presentation of the navigation drawer.
*/
private NavigationDrawerFragment mNavigationDrawerFragment;
/**
* Used to store the last screen title. For use in {@link #restoreActionBar()}.
*/
private CharSequence mTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
// Set up the drawer.
mNavigationDrawerFragment.setUp(
R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
}
@Override
public void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, PlaceholderFragment.newInstance(position + 1))
.commit();
}
public void onSectionAttached(int number) {
switch (number) {
case 1:
mTitle = getString(R.string.title_section1);
break;
case 2:
mTitle = getString(R.string.title_section2);
break;
case 3:
mTitle = getString(R.string.title_section3);
break;
case 4:
mTitle = getString(R.string.title_section4);
break;
}
}
public void restoreActionBar() {
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle(mTitle);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (!mNavigationDrawerFragment.isDrawerOpen()) {
// Only show items in the action bar relevant to this screen
// if the drawer is not showing. Otherwise, let the drawer
// decide what to show in the action bar.
getMenuInflater().inflate(R.menu.main, menu);
restoreActionBar();
return true;
}
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
public static final String ARG_OBJECT = "object";
private WebView webView;
/**
* Returns a new instance of this fragment for the given section
* number.
*/
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_OBJECT, sectionNumber);
fragment.setArguments(args);
return fragment;
}
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Bundle args = getArguments();
int position = args.getInt(ARG_OBJECT);
int tabLayout = 1;
switch (position) {
case 1:
tabLayout = R.layout.fragment_main;
break;
case 2:
tabLayout = R.layout.fashion;
break;
case 3:
tabLayout = R.layout.entertainment;
break;
case 4:
tabLayout = R.layout.computer;
break;
}
View rootView = inflater.inflate(tabLayout, container, false);
**webView = (WebView) rootView.findViewById(R.id.webView1);
if (webView != null) {
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("http://headgone.net/shop/index.php/motorsports");
}
webView = (WebView) rootView.findViewById(R.id.fashion);
if (webView != null) {
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("http://headgone.net/shop/index.php/headgone-clothing");
}
webView = (WebView) rootView.findViewById(R.id.entertainment);
if (webView != null) {
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.loadUrl("http://www.headgone.net/entertainment/index.php/homepage");
}
webView = (WebView) rootView.findViewById(R.id.computer);
if (webView != null) {
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("http://headgone.net/entertainment/index.php/computer-repairs");**
}
return rootView;
}
}}
여기서 실제로 무엇을하려고하는지 알 수 있습니다. –
메신저에 backpress를 추가하려고하면 현재 브라우징하는 동안 앱을 닫을 수 있습니다. on은 onbackpressed를 사용하여 업데이트되었지만 1 개의 webview에서만 작동합니다. 각 navdrawer 탭에 대한 webview가 있습니다. – user3084738
조각에 Backpressed 이벤트를 등록하지 않는 이유는 무엇입니까? – Areks