I am new to android development but after searching for a while i can not get a solution to maximise my webview in my android window (12080*800 in my current test). Same problem appear on the physical device (a samsung 10.1)
https://dl.dropbox.com/s/d57nmlhbs8pu6k7/2013-06-11%20at%2010.18.15.png
<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="match_parent"
android:gravity="top"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<WebView
android:id="#+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_margin="0dp"
android:padding="0dp"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" />
</RelativeLayout>
and my code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar and set fullscreen
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
// add the webview
WebView www = (WebView) findViewById(R.id.webView);
www.setWebViewClient(new WebViewClient());
www.getSettings().setJavaScriptEnabled(true);
www.getSettings().setDomStorageEnabled(true);
www.getSettings().setSavePassword(false);
www.getSettings().setSaveFormData(false);
www.getSettings().setUseWideViewPort(true);
// load html
www.loadUrl("http://192.168.1.8:3000/app/tgg4yme");
}
I have tried to fill the window through the editor too... no success
Thank you
Related
I just included an options menu in my app, but in one of my activities it seems to create a white empty space- can anyone tell me why??
It work in other activities in the same app, but not this single activity.
I Hope anyone can help :-)
public class GifsActivity extends OptionsMenu {
private Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gifs);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ImageView gifImageView = (ImageView) findViewById(R.id.iv_gif);
Glide.with(this)
.load("http://i.imgur.com/Vth6CBz.gif")
.asBitmap()
.placeholder(R.drawable.ic_cloud_off_red)
.error(R.drawable.ic_cloud_off_red)
.into(gifImageView);
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:gravity="center_vertical"
android:orientation="vertical"
tools:context="com.example.examand1.GifsActivity">
<include layout="#layout/toolbar_layout"
/>
<ImageView
android:id="#+id/iv_gif"
android:layout_width="match_parent"
android:layout_height="220dp" />
</RelativeLayout>
Picture of the activity
Remove android:gravity="center_vertical" from your layout. Then your layout will be as below:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="#+id/include"
layout="#layout/toolbar_layout"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
<ImageView
android:layout_below="#id/include"
android:id="#+id/iv_gif"
android:layout_width="match_parent"
android:layout_height="220dp" />
</RelativeLayout>
I put the photo of the account in the navigation header. The border is rectangular, I would like to make it rounded, how can I do that?
In this code I used Glide to display the image.
my_header_navigation.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"
android:layout_width="match_parent"
android:layout_height="140dp"
android:background="#color/common_google_signin_btn_text_dark_focused"
android:id="#+id/navigation_header">
<ImageView
android:id="#+id/photoImageView"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="16dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="18dp"
android:background="#color/colorAccent"
android:visibility="invisible" />
</RelativeLayout>
and in the Main Activity:
private ImageView photoImageView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
View hView = navigationView.getHeaderView(0);
photoImageView = hView.findViewById(R.id.photoImageView);
if(user != null){
Glide.with(List.this).load(user.getPhotoUrl()).into(photoImageView);
photoImageView.setVisibility(View.VISIBLE);
}
else{
photoImageView.setVisibility(View.INVISIBLE);
}
Your code i'ts right, you need implement CircleImageView, I show you how to implement.
CircleImageView - GitHub
nav_header_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="#dimen/nav_header_height"
android:background="#drawable/side_nav_bar"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:theme="#style/ThemeOverlay.AppCompat.Dark">
<com.mikhaellopez.circularimageview.CircularImageView
android:id="#+id/profile_image"
android:layout_width="150dp"
android:layout_height="150dp"
android:src="#drawable/profile_image"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:layout_marginBottom="0dp"
app:civ_border_color="#EEEEEE"
app:civ_border_width="4dp"
app:civ_shadow="true"
app:civ_shadow_radius="10"
app:civ_shadow_color="#8BC34A"/>
</LinearLayout>
MainActivity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CircleImageView circleImageView = (CircleImageView) findViewById(R.id.profile_image);
Glide.with(List.this).load(user.getPhotoUrl()).into(circleImageView);
}
My NavigationDrawer with CircleImageView
Link Image
NOTE
Remember, your image need proportional dimensioned, example (100x100, 200x200), like a perfect square, I hope I have help you.
I'm trying to create an app that uses Webview to connect to a raspberry pi web server I've created. It contains basically a few buttons that act as a garage door opener. For some reason, when I launch the app, it just displays a blank screen; but if I put in another website like Google in myWebView.loadUrl() , it loads just fine. I've added the
'<uses-permission android:name="android.permission.INTERNET" />'
inside the manifest
Here's the Activity:
public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("http://192.168.1.24:8000/garage.html");
}
}
Here is the xml in content_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.michael.garageopener.MainActivity"
tools:showIn="#layout/activity_main">
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
Am i doing anything wrong here?
So I'm done with my app and doing final tests. On Android 5.0+ it runs fine, but on pre Lollipop devices i get strange bug.
At first, action bar was not visible on activities with ScrollView and I fixed it by putting ScrollView inside of RelativeLayout. But that solves only half of the problem. Action bar color is transparent and I can tell that because background color in my activities is #f2f2f2 and text on Action bar is white.
I see action bar title, back button and all images I put in action bar, but just can't set the color of it to ColorPrimary which is material light blue.
Here's the ACTIVITY code (not content)
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="hr.app.liftme.liftmehr.VjezbeTricepsTricepsEkstenzijaKablovima">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay"
android:elevation="10dp"
app:elevation="10dp">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_vjezbe_triceps_triceps_ekstenzija_kablovima" />
</android.support.design.widget.CoordinatorLayout>
And here's java file where i declare
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vjezbe_triceps_triceps_ekstenzija_kablovima);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Can anyone please help me with this?
/** In your xml,color/background ,change according to your Requirement **/
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="55dp"
android:padding="#dimen/appbar_padding"
android:background="#color/appbarColor">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/place_order"
android:layout_gravity="center"
android:textSize="#dimen/appbar_txt_size"
android:textStyle="bold"
android:textColor="#color/white"
android:layout_marginTop="15dp"
android:id="#+id/toolbar_title"/>
</android.support.v7.widget.Toolbar>
/** In your java file **/
toolbar.setBackgroundColor(Color.parseColor("#617191"));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getActivity().getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(getActivity().getResources().getColor(R.color.toolbar));
}
I created a new project in Android. We use the following code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.web);
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://t.co/YoHe3NKrJH");
He is opening Chrome.
I need to close it automatically after 10s.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />