Hello guys im trying to do Tablayout in my project on android studio by following this https://github.com/codepath/android_guides/wiki/Google-Play-Style-Tabs-using-TabLayout (doing it up to the "Add Icons to TabLayout") Recently, but somehow my icon wont appear, already added style but still nothing appear, anyone know why?
Thanks
*note : i also try to create new project and copy the code exactly but the result is the same
on activity :
public class SlidingTabsActivity extends AppCompatActivity {
TabLayout tabLayout;
ViewPager viewPager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sliding_tabs);
viewPager = (ViewPager) findViewById(R.id.viewPager);
viewPager.setAdapter(new CustomAdapter(getSupportFragmentManager(), getApplicationContext()));
tabLayout = (TabLayout) findViewById(R.id.tabLayout);
tabLayout.setupWithViewPager(viewPager);
//set icon to tablayout
tabLayout.getTabAt(0).setIcon(R.drawable.clock);
tabLayout.getTabAt(1).setIcon(R.drawable.clock);
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
#Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
#Override
public void onTabUnselected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
#Override
public void onTabReselected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
});
}
private class CustomAdapter extends FragmentPagerAdapter {
private String viewfragment [] = {"slidingtab1","slidingtab2"};
private Context Mycontext;
public CustomAdapter(FragmentManager supportFragmentManager, Context applicationContext) {
super(supportFragmentManager);
this.Mycontext = applicationContext;
}
#Override
public Fragment getItem(int position) {
switch (position){
case 0:
return new SlidingTab1_Activity();
case 1:
return new SlidingTab2_Activity();
default:
return null;
}
}
#Override
public int getCount() {
return viewfragment.length;
}
}
}
On The xml :
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tabLayout"
android:background="#cdc36e"
app:tabMode="fixed"
app:tabGravity="fill"
style="#style/MyCustomTabLayout"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
Style
<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
<item name="tabTextAppearance">#style/MyCustomTextAppearance</item>
</style>
<style name="MyCustomTextAppearance" parent="TextAppearance.Design.Tab">
<item name="textAllCaps">false</item>
</style>
Related
I'm new to Android Studio and learning and help me to short out my issues. I'm unable to add onBackpress method in my webview fragment:
public class HomeFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View myView = inflater.inflate ( R.layout.fragment_home, container, false);
WebView myWebView = myView.findViewById ( R.id.home_webView );
myWebView.loadUrl ( "https://yahoo.com" );
WebSettings webSettings = myWebView.getSettings ();
webSettings.setJavaScriptEnabled ( true );
myWebView.setWebViewClient(new WebViewClient());
// Inflate the layout for this fragment
return myView;
}
#Override
public void onBackPressed() {
if (webView.canGoBack()) {
webView.goBack();
} else super.onBackPressed ();
}
}
}
This code is not working and my paystack payment gateway is not showing, though it displays the spinner but will not show the form for card input.
Please I need a complete code that will help me get my job done:
webView.setWebChromeClient(new WebChromeClient() {
#Override
public boolean onCreateWindow(WebView view, boolean isDialog,
boolean isUserGesture, Message resultMsg) {
WebView newWebView = new WebView(WebpageActivity.this);
newWebView.getSettings().setJavaScriptEnabled(true);
newWebView.getSettings().setSupportZoom(true);
newWebView.getSettings().setBuiltInZoomControls(true);
newWebView.getSettings().setPluginState(PluginState.ON);
newWebView.getSettings().setSupportMultipleWindows(true);
view.addView(newWebView);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(newWebView);
resultMsg.sendToTarget();
newWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
return true;
}
}
});
Well, this code should work when pasted on your MainActivity file of your android webview project.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.net.Uri;
import android.webkit.WebViewClient;
import android.webkit.WebSettings.PluginState;
public class MainActivity extends Activity {
private WebView webView = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.webView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = webView.getSettings();
webView.setInitialScale(1);
webSettings.setJavaScriptEnabled(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setUseWideViewPort(true);
webSettings.setAllowFileAccess(true);
webSettings.setAllowContentAccess(true);
webSettings.setSupportZoom(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setPluginState(PluginState.ON);
webSettings.setSupportMultipleWindows(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
WebViewClientImpl webViewClient = new WebViewClientImpl(this);
webView.setWebViewClient(webViewClient);
webView.loadUrl("https://www.your_url.com/");
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && this.webView.canGoBack()) {
this.webView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
public class WebViewClientImpl extends WebViewClient {
private Activity activity = null;
public WebViewClientImpl(Activity activity) {
this.activity = activity;
}
#Override
public boolean shouldOverrideUrlLoading(WebView webView, String url) {
if(url.indexOf("your_url") > -1 ) return false;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
activity.startActivity(intent);
return true;
}
}
}
Now, after pasting the above code you need to use the PHP paystack integration this time and not the javascript paystack integration initialization and callback functions.
At this point you only need to worry about your sessions.
Tested And Confirmed.
This question already has an answer here:
My recycler view is not showing any firebase images
(1 answer)
Closed 2 years ago.
My images from firebase are not showing in image view but the name of an image is showing in the above text view of the recycler view. Here is my code please help.
FragmentActivity
package com.example.bbeast.HomeActivity;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.bbeast.R;
import com.example.bbeast.Upload;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.squareup.picasso.Picasso;
import java.util.List;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
public class fragmentHealthTips extends Fragment {
private RecyclerView mRecyclerView;
private DatabaseReference mDataRef;
private Uri mImageuri;
View view;
public void fragmentHealthTips() {
}
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.healthtips_fragment, container, false);
mRecyclerView =(RecyclerView)view.findViewById(R.id.healthtips_recyclerView);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
mDataRef = FirebaseDatabase.getInstance().getReference().child("Uploads");
return view;
}
#Override
public void onStart() {
super.onStart();
FirebaseRecyclerOptions options =
new FirebaseRecyclerOptions.Builder<HealthTips>()
.setQuery(mDataRef, HealthTips.class)
.build();
FirebaseRecyclerAdapter<HealthTips, hViewHolder> adapter= new FirebaseRecyclerAdapter<HealthTips, hViewHolder>(options) {
#Override
protected void onBindViewHolder(#NonNull final hViewHolder holder, int i, #NonNull final HealthTips healthTips) {
//directly get the values like this
String Iname = healthTips.getName();
String Uimage = healthTips.getImage();
holder.hName.setText(Iname);
Picasso.get()
.load(Uimage)
.into(holder.hImageview);
}
#NonNull
#Override
public hViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.items_healthtips, parent, false);
hViewHolder viewHolder = new hViewHolder(view);
return viewHolder;
}
};
mRecyclerView.setAdapter(adapter);
adapter.startListening();
}
public static class hViewHolder extends RecyclerView.ViewHolder{
TextView hName;
ImageView hImageview;
public hViewHolder(#NonNull View itemView) {
super(itemView);
hName = itemView.findViewById(R.id.healthtips_name);
hImageview = itemView.findViewById(R.id.healthtips_imageView);
}
}
}
Xml file of items.
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/healthtips_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textSize="30sp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"/>
<ImageView
android:id="#+id/healthtips_imageView"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginTop="20dp"
android:background="#drawable/imageview_bg"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
Model class, Healthtips activity.
package com.example.bbeast.HomeActivity;
import java.util.jar.Attributes;
public class HealthTips {
public String name, image;
public HealthTips(){
}
public HealthTips(String name, String image){
this.name = name;
this.image = image;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public String getImage(){
return image;
}
public void setImage(String image){
this.image= image;
}
}
Gradle dependencies.
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.bbeast"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
dataBinding {
enabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
java.srcDirs = ['src/main/java', 'src/main/java/Admin Activity', 'src/main/java/com.example.bbeast/ui.main/Admin Activity']
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'com.google.firebase:firebase-database:16.0.4'
implementation 'com.google.firebase:firebase-storage:16.0.4'
implementation 'com.firebaseui:firebase-ui-database:3.2.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.firebase:firebase-analytics:16.0.5'
implementation 'com.google.firebase:firebase-auth:16.0.5'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.squareup.picasso:picasso:2.6.0-SNAPSHOT'
}
Please help me in getting an image in the image view. Thank you in advance.
Check
of the UImage is a valid path, normally I would do something like this..
P.S Not a RecyclerView but you get the idea
imageview1 = (ImageView) findViewById(R.id.imageview1);
_path_child_listener = new ChildEventListener() {
#Override
public void onChildAdded(DataSnapshot _param1, String _param2) {
GenericTypeIndicator<HashMap<String, Object>> _ind = new GenericTypeIndicator<HashMap<String, Object>>() {};
final String _childKey = _param1.getKey();
final HashMap<String, Object> _childValue = _param1.getValue(_ind);
Glide.with(getApplicationContext()).load(Uri.parse(_childValue.get("imageUrl").toString())).into(imageview1);
//imageUrl is pushed to Firebase Storage onUploadCompleted
}
#Override
public void onChildChanged(DataSnapshot _param1, String _param2) {
GenericTypeIndicator<HashMap<String, Object>> _ind = new GenericTypeIndicator<HashMap<String, Object>>() {};
final String _childKey = _param1.getKey();
final HashMap<String, Object> _childValue = _param1.getValue(_ind);
}
#Override
public void onChildMoved(DataSnapshot _param1, String _param2) {
}
#Override
public void onChildRemoved(DataSnapshot _param1) {
GenericTypeIndicator<HashMap<String, Object>> _ind = new GenericTypeIndicator<HashMap<String, Object>>() {};
final String _childKey = _param1.getKey();
final HashMap<String, Object> _childValue = _param1.getValue(_ind);
}
#Override
public void onCancelled(DatabaseError _param1) {
final int _errorCode = _param1.getCode();
final String _errorMessage = _param1.getMessage();
}
};
path.addChildEventListener(_path_child_listener);
}
private void initializeLogic() {
}
Some type of Urls are not loading in my app in Webview but it can be loaded in device browser. Following is the example Url which is not working in my code-
"http://apps.takeyourapp.com/testApp/staging/index.html"
package com.example.webviewdemo;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.LinearLayout.LayoutParams;
public class MainActivity extends Activity {
WebView webViewPlaceholder;
String URL = "http://apps.takeyourapp.com/testApp/staging/index.html";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webViewPlaceholder = (WebView) findViewById(R.id.webholder);
webViewPlaceholder.getSettings().setJavaScriptEnabled(true);
webViewPlaceholder
.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webViewPlaceholder.setScrollbarFadingEnabled(true);
webViewPlaceholder.getSettings().setLoadsImagesAutomatically(true);
webViewPlaceholder.getSettings().setUseWideViewPort(true);
webViewPlaceholder.loadUrl(URL);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Create WebViewClient and load url like
public class myWebClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
}
And setWebViewClient like:
webView.setWebViewClient(new myWebClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://apps.takeyourapp.com/testApp/staging/index.html");
And also add INTERNET permission into manifest.xml
<uses-permission android:name="android.permission.INTERNET" />
Try this solution.
public class Main extends Activity {
private WebView mWebview ;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mWebview = new WebView(this);
mWebview.getSettings().setJavaScriptEnabled(true); // enable javascript
final Activity activity = this;
mWebview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
}
});
mWebview .loadUrl("http://apps.takeyourapp.com/testApp/staging/index.html");
setContentView(mWebview );
}
}
I did a web to show different videos in HTML5,and the web works.
Now I would like to do a google tv app and show this web and work with it.
I try with a webView component but the part with javascript doesnt work and show like a plain text($function...) and the rest appear without any format.
This is my Activity:
public class Test extends Activity {
WebView mWebView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.vid);
mWebView = (WebView) findViewById(R.id.web);
mWebView.getSettings().setJavaScriptEnabled(true);
if (savedInstanceState != null) {
mWebView.restoreState(savedInstanceState);
} else {
mWebView.loadUrl("http://192.168.2.103:8080/VirtualSTBJSF/vid.xhtml");
mWebView.setWebViewClient(new verMiWeb());
}
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mWebView.saveState(outState);
}
#Override
public void onStop() {
super.onStop();
mWebView.stopLoading();
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && mWebView.canGoBack()) {
mWebView.goBack();
}
return super.onKeyDown(keyCode, event);
}
}
class verMiWeb extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
and the layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<WebView
android:id="#+id/web"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
Any idea?
Thanks for the answers.