I am developing an android news app and implemented toolbar as a back arrow when the user clicks should go to the back
I am developing an android news app and implemented toolbar as a back arrow when the user clicks should go to the back
below my DetailActivity where I have implemented toolbar
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;
import butterknife.BindView;
import butterknife.ButterKnife;
import edgar.yodgorbek.sportnews.R;
public class DetailActivity extends AppCompatActivity {
#BindView(R.id.toolbar)
Toolbar toolbar;
#BindView(R.id.imageView)
ImageView imageView;
#BindView(R.id.webView)
WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
String imageUrl = getIntent().getExtras().getString("imageKey");
Picasso.get().load(imageUrl).into(imageView);
webView.getSettings().setJavaScriptEnabled(true);
String url = getIntent().getExtras().getString("urlKey");
webView.setWebViewClient(new WebViewClient());
webView.loadUrl(url);
}
#Override
public boolean onSupportNavigateUp() {
onBackPressed();
return true;
}
public class WebViewController extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
below my activity_detail.xml
<android.support.design.widget.CoordinatorLayout 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:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar"
android:layout_marginTop="32dp"
tools:ignore="ContentDescription" />
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView" />
</android.support.design.widget.CoordinatorLayout>
Related
I have found it impossible to correctly set the autocompletion of fields in html forms in an android studio webview:
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
tools:context=".MainActivity">
<RelativeLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ProgressBar
android:id="#+id/progressbar_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF" />
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:usesCleartextTraffic="true" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
MainActivity.java:
package com.example.webview;
import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
public class MainActivity extends AppCompatActivity {
private WebView myWebView;
private ProgressBar progressBar;
#SuppressLint("SetJavaScriptEnabled")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myWebView = findViewById(R.id.webview);
progressBar = findViewById(R.id.progressbar_id);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
webSettings.setGeolocationEnabled(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setSaveFormData(true);
WebViewClient webViewClient = new WebViewClient(){
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
progressBar.setVisibility(View.VISIBLE);
myWebView.setVisibility(View.GONE);
}
#Override
public void onPageFinished(WebView view, String url) {
progressBar.setVisibility(View.GONE);
myWebView.setVisibility(View.VISIBLE);
}
};
myWebView.setWebViewClient(webViewClient);
myWebView.setSoundEffectsEnabled(true);
myWebView.loadUrl("https://tcg-wallet.ga/home");
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Check if the key event was the Back button and if there's history
if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) {
myWebView.goBack();
return true;
}
// If it wasn't the Back key or there's no web page history, bubble up to the default
// system behavior (probably exit the activity)
return super.onKeyDown(keyCode, event);
}
}
i have try using:
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
but nothing happens there are no suggestions, I expected something like:
I don't know what I need to add to enable those suggestions!
I have a linear layout carrying webview. I have set the id of the LinearLayout to 'lay001'.
My intention is to set the onClickListener of the layout so that onclick, the intent will send data to webview and then to the url i specified.
All my efforts to make it work failed me. Please help me set the java code. Thanks
activity_main.xml
<LinearLayout
android:id="#+id/lay001"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:layout_margin="4dp"
android:orientation="vertical"
android:background="#drawable/layout_bg1">
<WebView
android:id="#+id/webview001"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:accessibilityPaneTitle="The Liturgy"
android:layout_marginTop="2dp">
</WebView>
<TextView
android:id="#+id/textView001"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
android:text="Anglican Hymns Tunes"
android:textSize="10sp"
android:textStyle="italic|bold"
android:textAlignment="center"
android:textColor="#DD1A1A"/>
</LinearLayout>
MainActivity.java
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
private WebView webview;
private LinearLayout myLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myLayout.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
webview = (WebView001) findViewById(R.id.webview001);
webview.setWebViewClient(new WebViewClient());
webview.loadUrl("http://www.google.com");
}
}
});
}
}
You are missing findViewById() of linearlayout.
Try this out :
private LinearLayout myLayout;
myLayout= (LinearLayout) findViewById(R.id.lay001);
Also change this :
webview = (WebView) findViewById(R.id.webview001);
To load url :
myLayout.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
mWebview.loadUrl("your url");
}
});
I can't use WebView correctly. When I run my app there is "What to use" window and buttons "Browser, Chrome, Sorting" On Clicking "Отмена"/"Cancel" there is nothing happen. There are no errors in my code and I really don't know how to use WebView correctly. Please help me. "What to use" window
But I add WebView and I want to show everything in it. There is my code:
Main_Activity.java
package com.admin.zabroshki;
import android.annotation.SuppressLint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#SuppressLint("ResourceType")
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
// получим идентификатор выбранного пункта меню
int id = item.getItemId();
String urlVK = new String("https://vk.com/zabroshkiborika");
String urlInstagram = new
String("https://instagram.com/zabroshkiborika");
WebView view = (WebView) findViewById(R.id.webView);
view.getSettings().setJavaScriptEnabled(true);
view.getSettings().setLoadWithOverviewMode(true);
view.getSettings().setUseWideViewPort(true);
switch (id)
{
case R.id.urlVK:
view.loadUrl(urlVK);
break;
case R.id.Instagram:
view.loadUrl(urlInstagram);
break;
}
return false;
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
tools:context="com.admin.zabroshki.MainActivity">
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
You try this.
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setAllowContentAccess(true);
settings.setDomStorageEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("https://vk.com/zabroshkiborika");
I'm following a tutorial on this Lapit Chat App - All Users Activity - Firebase Tutorials - Part 14. But i get my application to be corrupted when retrieving data from firebase. For previous tutorials all goes well without error. Just for this topic my app crashes. And all my code is the same as in the tutorial.
UserActivity.java
package com.bertho.chat;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class UsersActivity extends AppCompatActivity {
private Toolbar mToolbar;
private RecyclerView mUsersList;
private DatabaseReference mUsersDatabase;
private ProgressDialog mDialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_users);
mDialog = new ProgressDialog(this);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setTitle("User List");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mUsersDatabase = FirebaseDatabase.getInstance().getReference().child("Users");
mUsersList = (RecyclerView) findViewById(R.id.users_list);
mUsersList.setHasFixedSize(true);
mUsersList.setLayoutManager(new LinearLayoutManager(this));
}
#Override
protected void onStart() {
super.onStart();
showLoading("Get all user data");
FirebaseRecyclerAdapter<Users, UsersViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Users, UsersViewHolder>(
Users.class,
R.layout.users_single_layout,
UsersViewHolder.class,
mUsersDatabase
) {
#Override
protected void populateViewHolder(UsersViewHolder usersViewHolder, Users users, int position) {
usersViewHolder.setDisplayName(users.getName());
mDialog.dismiss();
}
};
mUsersList.setAdapter(firebaseRecyclerAdapter);
}
public static class UsersViewHolder extends RecyclerView.ViewHolder {
View mView;
public UsersViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setDisplayName(String name) {
TextView userNameView = (TextView) mView.findViewById(R.id.user_single_name);
userNameView.setText(name);
}
}
private void showLoading(String s) {
mDialog.setTitle("Please waiting");
mDialog.setMessage(s);
mDialog.setCanceledOnTouchOutside(false);
mDialog.show();
}
}
activity_users.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context="com.bertho.chat.UsersActivity">
<include layout="#layout/app_bar_layout"
android:id="#+id/user_appBar">
</include>
<android.support.v7.widget.RecyclerView
android:id="#+id/users_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/user_appBar">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
users_single_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#color/bgAbuAbu">
<android.support.v4.widget.CircleImageView
android:id="#+id/user_single_image"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_margin="10dp"
android:src="#drawable/notfound" />
<TextView
android:id="#+id/user_single_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/user_single_image"
android:layout_marginTop="14dp"
android:layout_toEndOf="#+id/user_single_image"
android:layout_toRightOf="#+id/user_single_image"
android:text="User default name!"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/user_single_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/user_single_name"
android:layout_marginTop="11dp"
android:layout_toEndOf="#+id/user_single_image"
android:layout_toRightOf="#+id/user_single_image"
android:text="User default status!" />
</RelativeLayout>
And my of Error Log on android studio
https://pastebin.com/UKhPswXQ
Is there anything wrong or missing on my code? Please help
your CircularImageView is not inflated and there was so many problems about it, solution use alternative library like hdodenhof CircularImageView link
add this to your dependencies :
compile 'de.hdodenhof:circleimageview:2.1.0'
and add the view like this :
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/profile_image"
android:layout_width="96dp"
android:layout_height="96dp"
android:src="#drawable/profile"
app:civ_border_width="2dp"
app:civ_border_color="#FF000000"/>
I'm trying to create a navigation drawer with swipe tab. But my viewpager is not working fine. I can only select the tab. Viewpager can not load any fragment. so I can not swipe it. If i change the height of the viewpager it hides the tab and load all the fragment.
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<include
android:id="#+id/app_bar"
layout="#layout/app_bar" />
<android.support.v4.widget.DrawerLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/drawer_layout">
<FrameLayout
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<android.support.design.widget.TabLayout
android:id="#+id/sliding_tab"
style="#style/MyCustomTabLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
app:tabMode="scrollable" />
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#android:color/white" />
</FrameLayout>
<fragment
android:id="#+id/nav_drawer"
android:name="com.example.usaukglu.tablayoyt.NavigationDrawer"
android:layout_width="#dimen/drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="#layout/navigation_drawer"
tools:layout="#layout/navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
Here is my MainActivity.java Code:
package com.example.usaukglu.tablayoyt;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.LinearLayout;
public class MainActivity extends AppCompatActivity {
private Toolbar toolbar;
NavigationDrawer navigationDrawer;
DrawerLayout drawerLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_appbar);
ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
TabLayout tabLayout= (TabLayout) findViewById(R.id.sliding_tab);
toolbar= (Toolbar) findViewById(R.id.app_bar);
drawerLayout= (DrawerLayout) findViewById(R.id.drawer_layout);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
viewPager.setAdapter(new ViewPagerAdapter(getSupportFragmentManager(),MainActivity.this));
tabLayout.setupWithViewPager(viewPager);
navigationDrawer= (NavigationDrawer) getSupportFragmentManager().findFragmentById(R.id.nav_drawer);
navigationDrawer.setUp(R.id.nav_drawer,drawerLayout,toolbar);
}
}
Here is my ViewpagerAdapter.java code
package com.example.usaukglu.tablayoyt;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentStatePagerAdapter;
class ViewPagerAdapter extends FragmentPagerAdapter {
final int PAGE_COUNT = 3;
private String tabTitles[] = new String[] { "Tab1", "Tab2", "Tab3" };
private Context context;
public ViewPagerAdapter(FragmentManager fm, Context context) {
super(fm);
this.context = context;
}
#Override
public int getCount() {
return PAGE_COUNT;
}
#Override
public Fragment getItem(int position) {
Fragment fragment=null;
if (position==0){
fragment=new FragmentPage();
}
if (position==1){
fragment=new FragmentExpense();
}
if (position==2){
fragment=new FragmentIncome();
}
return fragment;
}
#Override
public CharSequence getPageTitle(int position) {
// Generate title based on item position
return tabTitles[position];
}
}
You shouldn't use FrameLayout as container for the tab + pager. FrameLayout is used mostly to put views above others. To fix it you should change this FrameLayout to LinearLayout with vertical orientation. Also the view page height should be match_parent.