Android tabview icon not show - android-tabs

Tabbar icon not showing
I try change res.getDrawble(R.drawble.ic_alarm) but not showed.
I use Fragment/ViewPager so make FakeContent
tabHost = (TabHost)findViewById(R.id.tabHost);
tabHost.setup();
TabHost.TabSpec tabSpec;
Resources res = getResources();
tabSpec = tabHost.newTabSpec("Tab1");
tabSpec.setIndicator("Tab1", res.getDrawable(R.drawable.alarm));
tabSpec.setContent(new FakeContent(getApplicationContext()));
tabHost.addTab(tabSpec);
tabSpec = tabHost.newTabSpec("Tab2");
tabSpec.setIndicator("Tab2", getResources().getDrawable(R.drawable.ic_alarm));
tabSpec.setContent(new FakeContent(getApplicationContext()));
tabHost.addTab(tabSpec);
tabSpec = tabHost.newTabSpec("Tab3");
tabSpec.setIndicator("Tab3",getResources().getDrawable(R.drawable.ic_alarm));
tabSpec.setContent(new FakeContent(getApplicationContext()));
tabHost.addTab(tabSpec);
tabHost.setOnTabChangedListener(this);
XML ic_alarm
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/alarm" android:state_selected="true" />
</selector>

Related

How to persist a choice in a Xamarin Android alert dialog

This dialog box displays correctly, except that the user's choice is not captured:
var dialogView = LayoutInflater.Inflate(Resource.Layout.list_view, null);
Android.App.AlertDialog alertDialog;
var items = new string[] { "A","B","C" };
var adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, items);
using (var dialog = new Android.App.AlertDialog.Builder(this))
{
dialog.SetTitle("Choose Letter");
dialog.SetMessage("Just Click!");
dialog.SetView(dialogView);
dialog.SetNegativeButton("Cancel", (s, a) => { });
dialog.SetPositiveButton("OK", (s, a) => {
{
if (a.Which!=-1)
//BUT I don't know how to persist the choice
//when I click on one of the letters, it briefly
//shows the choice (the background is briefly grayed
//but the choice doesn't persist
//so when I click OK, a.Which is -1
{
//do things with the choice
}
}});
alertDialog = dialog.Create();
}
dialogView.FindViewById<ListView>(Resource.Id.listview).Adapter = adapter;
alertDialog.Show();
}
And this is the axml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
How do I 1) show the user's choice more than the line being briefly grayed and 2) how do I persist that choice?
Do you want to achieve the result like following GIF?
If so, you can create a ListItem to replace the Android.Resource.Layout.SimpleListItem1
Here is my ListItem
var adapter = new ArrayAdapter<string>(this, Resource.Layout.list_item, items);
list_item
<?xml version="1.0" encoding="utf-8" ?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/mybackground"
android:gravity="center_vertical"
android:padding="3dp"
android:textSize="20sp"
/>
mybackground
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#android:color/background_light"
android:state_pressed="false" android:state_selected="false"/>
<item android:drawable="#android:color/background_dark"
android:state_pressed="true"/>
<item android:drawable="#color/light_blue" android:state_pressed="false"
android:state_selected="true"/>
And achieve the listview.ItemClick += Listview_ItemClick;
private void Listview_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
{
e.View.Selected = true;
}
Here is my demo.
https://github.com/851265601/Xamarin.Android_ListviewSelect

How to persist a choice in a Xamarin Alert Dialog [duplicate]

This dialog box displays correctly, except that the user's choice is not captured:
var dialogView = LayoutInflater.Inflate(Resource.Layout.list_view, null);
Android.App.AlertDialog alertDialog;
var items = new string[] { "A","B","C" };
var adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, items);
using (var dialog = new Android.App.AlertDialog.Builder(this))
{
dialog.SetTitle("Choose Letter");
dialog.SetMessage("Just Click!");
dialog.SetView(dialogView);
dialog.SetNegativeButton("Cancel", (s, a) => { });
dialog.SetPositiveButton("OK", (s, a) => {
{
if (a.Which!=-1)
//BUT I don't know how to persist the choice
//when I click on one of the letters, it briefly
//shows the choice (the background is briefly grayed
//but the choice doesn't persist
//so when I click OK, a.Which is -1
{
//do things with the choice
}
}});
alertDialog = dialog.Create();
}
dialogView.FindViewById<ListView>(Resource.Id.listview).Adapter = adapter;
alertDialog.Show();
}
And this is the axml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
How do I 1) show the user's choice more than the line being briefly grayed and 2) how do I persist that choice?
Do you want to achieve the result like following GIF?
If so, you can create a ListItem to replace the Android.Resource.Layout.SimpleListItem1
Here is my ListItem
var adapter = new ArrayAdapter<string>(this, Resource.Layout.list_item, items);
list_item
<?xml version="1.0" encoding="utf-8" ?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/mybackground"
android:gravity="center_vertical"
android:padding="3dp"
android:textSize="20sp"
/>
mybackground
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#android:color/background_light"
android:state_pressed="false" android:state_selected="false"/>
<item android:drawable="#android:color/background_dark"
android:state_pressed="true"/>
<item android:drawable="#color/light_blue" android:state_pressed="false"
android:state_selected="true"/>
And achieve the listview.ItemClick += Listview_ItemClick;
private void Listview_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
{
e.View.Selected = true;
}
Here is my demo.
https://github.com/851265601/Xamarin.Android_ListviewSelect

Having problems saving camera images

I have been through the contents and cant seem to find an answer to my issue.
I have an imagefile in my app, and a button... I am following the tutorial on android developers https://developer.android.com/training/camera/photobasics#java but am having problems saving the file. At one point, I was able to save to cache, but i would rather save to a folder in pictures.
Here is my code...
static final int REQUEST_IMAGE_CAPTURE = 1;
private void dispatchTakePictureIntent() {
Intent dispatchTakePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (dispatchTakePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
photoFile = createImageFile();
// Continue only if the File was successfully created
if (photoFile != null) {
Uri photoURI = FileProvider.getUriForFile(this,
"com.example.ConfinedSpaceManagement",
photoFile);
dispatchTakePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(dispatchTakePictureIntent, REQUEST_TAKE_PHOTO);
}
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
imageView.setImageBitmap(imageBitmap);
}
}
String currentPhotoPath;
private File createImageFile(){
// Create an image file name
File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
if (!storageDir.exists()) {
if (!storageDir.mkdirs()) {
Log.d("Confined_Space", "failed to create Directory");
return null;
}
}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
return new File(storageDir.getPath() + File.separator + "ConSp" + timeStamp + ".jpg");
}
//String imageFileName = "JPEG_" + timeStamp + "_";
////////////////////////////////////////////////////////////////
static final int REQUEST_TAKE_PHOTO = 1;
}
and this is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.confinedspacemanagement">
<uses-feature android:name="android.hardware.camera"
android:required="false" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<meta-data
android:name="com.google.android.actions"
android:resource="#xml/file_paths" />
<activity android:name=".Signature" />
<activity android:name=".AuditWork" />
<activity android:name=".DisplayIndividual" />
<activity android:name=".SecondActivity" />
<activity android:name=".Definition" />
<activity
android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.example.confinedspacemanagement.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths"/>
</provider>
</application>
</manifest>
and here is my xml.file_path
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="my_images" path="Android/data/com.example.package.name/files/Pictures" />
</paths>
The activity is a sqlite form page. I am trying to take a picture, save it to a specified file, and then save the file path into the database.
Any help out there??? Should I be using camera2???
I found an answer at https://www.youtube.com/watch?v=VqgZxiU2knM by Mr. PRABEESH R K.
The image is saving fine, but I am taking the picture from an activity that is not the main activity. When I return the result, the page goes back to main activity, not the page the camera was originally requested from. Is there any way to keep it on the sending page?

SlidingPanel for Xamarin.Android

I'm creating a slide view with 2 tabs, but I don't know why the part of tabs are "transparent", they take the background color and not the AppBar color..anyone knows why?
MainActivity:
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Support.Design.Widget;
using Android.Support.V4.View;
namespace M_v1
{
[Activity(Label = "M_v1", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
SetContentView(Resource.Layout.Main);
TabLayout tabLayout = (TabLayout)FindViewById(Resource.Id.tablayout_navigation);
ViewPager viewPager = (ViewPager)FindViewById(Resource.Id.pager);
SetupviewPager(viewPager);
tabLayout.SetupWithViewPager(viewPager);
}
private void SetupviewPager(ViewPager viewPager)
{
viewPager.OffscreenPageLimit = 2;
PageAdapter adapter = new PageAdapter(SupportFragmentManager);
adapter.AddFragment(new Fragment1(), "One");
adapter.AddFragment(new Fragment2(), "Two");
viewPager.Adapter = adapter;
}
}
}
Here the theme:
<style name = "AppTheme" parent = "Theme.AppCompat.Light.NoActionBar">
<item name = "windowActionBar">true</item>
<item name ="windowNoTitle">false</item>
<item name ="colorPrimary">#2B5C56</item>
<item name ="colorPrimaryDark">#000000</item>
<item name ="colorAccent">#FFEE58</item>
</style>
Having the problem that the new TabLayout uses the indicator colour from the value colorAccent, I decided to dig into the android.support.design.widget.TabLayout implementation, finding that there are no public methods to customize this. However, I found this style specification of the TabLayout:
<style name="Base.Widget.Design.TabLayout" parent="android:Widget">
<item name="tabMaxWidth">#dimen/tab_max_width</item>
<item name="tabIndicatorColor">?attr/colorAccent</item>
<item name="tabIndicatorHeight">2dp</item>
<item name="tabPaddingStart">12dp</item>
<item name="tabPaddingEnd">12dp</item>
<item name="tabBackground">?attr/selectableItemBackground</item>
<item name="tabTextAppearance">#style/TextAppearance.Design.Tab</item>
<item name="tabSelectedTextColor">?android:textColorPrimary</item>
Having this style specification, now we can customize the TabLayout like this:
<android.support.design.widget.TabLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#id/pages_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:tabIndicatorColor="#android:color/white"
app:tabIndicatorHeight="4dp"/>

android how to show progress dialog on snackBar?

Is there way to show progress dialog on snackBar while getting data from server for pagination inside AsyncTask.If is this possible then how to do this.Please give suggestions.
For new design library:
if you want to show progressBar in left side:
Snackbar bar = Snackbar.make(root, R.string.data_updating, Snackbar.LENGTH_INDEFINITE);
ViewGroup contentLay = (ViewGroup) bar.getView().findViewById(android.support.design.R.id.snackbar_text).getParent();
ProgressBar item = new ProgressBar(context);
contentLay.addView(item,0);
bar.show();
or in right side:
Snackbar bar = Snackbar.make(root, R.string.data_updating, Snackbar.LENGTH_INDEFINITE);
ViewGroup contentLay = (ViewGroup) bar.getView().findViewById(android.support.design.R.id.snackbar_text).getParent();
ProgressBar item = new ProgressBar(context);
contentLay.addView(item);
bar.show();
the easiest and the best approach would be this:
Snackbar bar = Snackbar.make(layout, "Somthing", Snackbar.LENGTH_INDEFINITE);
Snackbar.SnackbarLayout snack_view = bar.getView();
snack_view.addView(new ProgressBar(context));
bar.show();
SnackbarLayout extends LinearLayout, so you can add view as a child or customize it the way you want.
for example to change the style of the TextView inside SnackBar you can do this:
TextView tv = (TextView) bar.getView().findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
tv.setTextSize(0, dimen[1] / 40);
tv.setTypeface(Typeface.createFromAsset(context.getAssets(),"fonts/font.otf"));
I've written a library that do just that. It also includes queue system. Try it out https://github.com/tingyik90/snackprogressbar
Kotlin 2021:
fun showLoadingSnackbar(){
val snackbar: Snackbar = Snackbar.make(findViewById(R.id.rootlayoutid), "TEXT or RES", Snackbar.LENGTH_INDEFINITE)
val viewGroup = snackbar.view.findViewById<View>(com.google.android.material.R.id.snackbar_text).parent as ViewGroup
viewGroup.addView(ProgressBar(this))// Or Context if not in Activity
snackbar.show()
}
If you want it on the left simply call addView(ProgressBar(this),0) instead as mentioned in the other answer
Edit: The answer has the progressbar at the top if the text is too long, so for it to be centered you can do this:
val snackbar: Snackbar = Snackbar.make(this, text, duration)
val viewGroup = snackbar.view.findViewById<View>(com.google.android.material.R.id.snackbar_text).parent as ViewGroup
viewGroup.addView(ProgressBar(context).also {
it.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)
it.foregroundGravity = Gravity.CENTER_VERTICAL
})
snackbar.show()
I think you could style a custom progress dialog to look like a Snackbar, since snackbar doesn't prevent user interaction with GUI while loading.
Update:
Try this:
Create anim res file name it slide_in.xml and paste this:
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="50%p" android:toYDelta="0%p"
android:duration="#android:integer/config_longAnimTime"
/>
create another anim res file name it slide_out.xml:
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="#android:integer/config_longAnimTime"
android:fromYDelta="0%p"
android:toYDelta="100%p" />
now place process dialog style in style res:
<style name="CustomDialog" parent="#android:style/Theme.Holo.Dialog">
<item name="android:windowMinWidthMajor">100%</item>
<item name="android:windowMinWidthMinor">100%</item>
<item name="android:background">#323232</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:windowBackground">#color/transparent</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:alertDialogStyle">#style/customDialogStyle</item>
<item name="android:windowAnimationStyle">#style/DialogAnimation</item>
</style>
<style name="customDialogStyle">
<item name="android:bottomBright">#android:color/transparent</item>
<item name="android:bottomDark">#android:color/transparent</item>
<item name="android:bottomMedium">#android:color/transparent</item>
<item name="android:centerBright">#android:color/transparent</item>
<item name="android:centerDark">#android:color/transparent</item>
<item name="android:centerMedium">#android:color/transparent</item>
<item name="android:fullBright">#android:color/transparent</item>
<item name="android:fullDark">#android:color/transparent</item>
<item name="android:topBright">#android:color/transparent</item>
<item name="android:topDark">#android:color/transparent</item>
Place this for animation:
<style name="DialogAnimation">
<item name="android:windowEnterAnimation">#anim/slide_in</item>
<item name="android:windowExitAnimation">#anim/slide_out</item>
</style>
Now add you method:
public static ProgressDialog processSnackbar(Context context,String s){
ProgressDialog pSnackbar = new ProgressDialog(context, R.style.CustomDialog) {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ProgressBar progress = (ProgressBar) findViewById(android.R.id.progress);
LinearLayout bodyLayout = (LinearLayout) progress.getParent();
TextView messageView = (TextView) bodyLayout.getChildAt(1);
messageView.setPadding(20,0,0,0);
LinearLayout.LayoutParams llp =
(LinearLayout.LayoutParams) messageView.getLayoutParams();
llp.width = 0;
llp.weight = 1;
bodyLayout.removeAllViews();
bodyLayout.addView(messageView, llp);
bodyLayout.addView(progress);
}
};
pSnackbar.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pSnackbar.setMessage(s);
pSnackbar.getWindow().setGravity(Gravity.BOTTOM);
pSnackbar.setCancelable(false);
return pSnackbar;
}
Method Credit returns to #mike-m reference Is it possible to alter progress dialog's message or spinner position?
I am using this as well in my application take a look:

Resources