I use canhub to crop image. Even I load the image, it is not shown. When I log the uri or canhub imageviewer, it is not null. I added the permissions and checked manually, there is no problem about permissions.
My main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.canhub.cropper.CropImageView
android:id="#+id/CropImageView"
android:layout_width="400dp"
android:layout_height="400dp"
android:layout_weight="1"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="5dp"
tools:layout_editor_absoluteY="61dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
and MainActivity.java
public class MainActivity extends AppCompatActivity {
CropImageView mCropImageView;
Uri mCropImageUri;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mCropImageView = (CropImageView)findViewById(R.id.CropImageView);
//ImageView test = findViewById(R.id.test);
Uri uri = Uri.parse("android.resource://com.example.testaygaz/drawable/bird.jpg");
Log.i("MainActivity",mCropImageView.toString());
//test.setImageURI(uri);
mCropImageView.setImageUriAsync(uri);
}
}
Related
package com.example.appthree;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String Htmlurl = "file://android_assets/index.html";
WebView view = (WebView) this.findViewById(R.id.webView);
view.getSettings().setJavaScriptEnabled(true);
view.loadUrl(Htmlurl);
}
}
This is my MainActivity.java file. I want to rander html file on app which is inside the assets folder. But I'm getting this error ->
error: cannot find symbol
WebView view = (WebView) this.findViewById(R.id.webView);
^
symbol: variable webView
location: class id
see screenshot (https://prnt.sc/yx65CzqLDBmk)
Updated____
this is my activity_main.xml file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome"
android:textSize="48sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.421"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.043" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World"
tools:layout_editor_absoluteX="136dp"
tools:layout_editor_absoluteY="193dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
You need to add the WebView inside the ConstraintLayout as Halil Ozel's code. Something like this
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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">
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome"
android:textSize="48sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.421"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.043" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World"
tools:layout_editor_absoluteX="136dp"
tools:layout_editor_absoluteY="193dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
You need to add internet permission in AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
Make sure that your id of webView component into activity_main.xml is webView.
WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
I'm creating a Listview that shows the names of the days in a week. The app crashes and the logcat doesn't show anything. How to solve this issue?
MainActivity.java
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView lv_classTimetable = (ListView) findViewById(R.id.lv_classTimetable);
ArrayList<String> lvDays = new ArrayList<>();
lvDays.add("Monday");
lvDays.add("Tuesday");
lvDays.add("Wednesday");
lvDays.add("Thursday");
lvDays.add("Friday");
lvDays.add("Saturday");
lvDays.add("Sunday");
ArrayAdapter classListAdapter = new ArrayAdapter(MainActivity.this, R.layout.class_timetable_listview_layout, lvDays);
lv_classTimetable.setAdapter(classListAdapter);
}
}
activity_main.xml
<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"
android:padding="16dp"
tools:context=".MainActivity">
<ListView
android:id="#+id/lv_classTimetable"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:dividerHeight="5dp"
android:divider="#d1d1d1"></ListView>
</RelativeLayout>
class_timetable_listview_layout.xml this is the layout for the custom listview
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp">
<TextView
android:id="#+id/lv_day"
android:gravity="center"
android:textAlignment="center"
android:text="Day"
android:textStyle="bold"
android:textSize="35sp"
android:layout_width="match_parent"
android:layout_height="60dp"/>
</LinearLayout>
Credit to #Mike M. Solution:
The LinearLayout should change to TextView. class_timetable_listview_layout.xml should change to
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="76dp"
android:layout_margin="10dp"
android:gravity="center"
android:textAlignment="center"
android:text="Day"
android:textStyle="bold"
android:textSize="35sp">
</TextView>
MainActivity.java
ArrayAdapter classListAdapter = new ArrayAdapter(this, R.layout.class_timetable_listview_layout, lvDays );
lv_classTimetable.setAdapter(classListAdapter);
I'm implementing a marquee effect but its not working on Android Studio.
This is the code
This is the .xml file part for the textview:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/logos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="36dp"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:fontFamily="serif-monospace"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="TRAVEL PORTAL"
android:textSize="36sp"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="62dp" />
This is my main_activity code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView logos = findViewById(R.id.logos);
logos.setEllipsize(TextUtils.TruncateAt.MARQUEE);
logos.setSelected(true);
}
I'm writing an application in Android where background is a map and I want to put on this background some buttons like "Search", "Login".
I have created xml like below:
<?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="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:id="#+id/buttonLogReg"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_gravity="top"
android:layout_weight="10"
android:baselineAligned="false"
android:text="#string/log_amp_reg"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<org.osmdroid.views.MapView
android:id="#+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:ignore="MissingConstraints" >
</org.osmdroid.views.MapView>
<org.osmdroid.views.MapView
android:id="#+id/mapview"
tilesource="Mapnik"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
and also Java code like:
public class MainActivity extends Activity {
MapView map = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Context ctx = getApplicationContext();
Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));
setContentView(R.layout.activity_main);
map = (MapView)findViewById(R.id.map);
map.setTileSource(TileSourceFactory.MAPNIK);
map.setBuiltInZoomControls(true);
map.setMultiTouchControls(true);
IMapController mapController = map.getController();
mapController.setZoom(12.5);
GeoPoint startPoint = new GeoPoint(49.20, 19.94);
mapController.setCenter(startPoint);
Button logreg = findViewById(R.id.buttonLogReg);
logreg.setOnClickListener(onClickListener);
}
public void onResume(){
super.onResume();
map.onResume();
}
public void onPause(){
super.onPause();
map.onPause();
}
private View.OnClickListener onClickListener = new View.OnClickListener(){
#Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(), LoginRegister.class);
startActivity(intent);
}
};
}
So my question is:
Why I can't see the button on android screen, I see only moveable map?
Anybody could help me with this issue?
There are two problem maps in the map sizes. You can edit them.......
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:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity">
<Button
android:id="#+id/buttonLogReg"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_gravity="top"
android:layout_weight="10"
android:text="#string/log_amp_reg" />
<org.osmdroid.views.MapView
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="100dp"
tools:ignore="MissingConstraints" >
</org.osmdroid.views.MapView>
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.