Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
How can I achieve something like the top bar in the screenshot ("Totale Regioni Province") using a tabbed page custom renderer? Right now I'm using "fake tabs" made of three different labels.
I need to change font family, font size and padding of the tabs.
When you want to change the font of tab page, you could use the custom renderer to reset it.
MyTabbedPageRenderer.cs:
[assembly: ExportRenderer(typeof(MainPage), typeof(MyTabbedPageRenderer))]
namespace TabbedPageDemo.Droid
{
class MyTabbedPageRenderer : TabbedPageRenderer
{
public MyTabbedPageRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<TabbedPage> e)
{
base.OnElementChanged(e);
if (e.NewElement == null || e.OldElement != null)
return;
TabLayout tablayout = (TabLayout)ViewGroup.GetChildAt(1);
Android.Views.ViewGroup vgroup = (Android.Views.ViewGroup)tablayout.GetChildAt(0);
for (int i = 0; i < vgroup.ChildCount; i++)
{
Android.Views.ViewGroup vvgroup = (Android.Views.ViewGroup)vgroup.GetChildAt(i);
Typeface fontFace = Typeface.CreateFromAsset(this.Context.Assets, "Trashtalk.ttf");
for (int j = 0; j < vvgroup.ChildCount; j++)
{
Android.Views.View vView = (Android.Views.View)vvgroup.GetChildAt(j);
if (vView.GetType() == typeof(Android.Support.V7.Widget.AppCompatTextView) || vView.GetType() == typeof(Android.Widget.TextView))
{
//here change textview style
TextView txtView = (TextView)vView;
txtView.TextSize = 14f;
txtView.SetTypeface(fontFace, TypefaceStyle.Normal);
}
}
}
}
}
}
I use a Tabbed page template project for example.
Update:
Create a Font folder in Resource. Add .ttf file and myfont.xml in it.
<?xml version="1.0" encoding="utf-8" ?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
<font android:font="#font/Samantha"
android:fontStyle="normal"
android:fontWeight="400"
app:font="#font/Samantha"
app:fontStyle="normal"
app:fontWeight="400"/>
</font-family>
Style.xml
<style name="MyTabLayout" parent="Base.Widget.Design.TabLayout">
<item name="tabTextAppearance">#style/MyTabTextAppearance</item>
</style>
<style name="MyTabTextAppearance" parent="TextAppearance.AppCompat.Button">
<item name="android:textSize">20sp</item>
<item name="android:fontFamily">#font/myfont</item>
</style>
Apply styles in Tabbar.xml.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.TabLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:tabIndicatorColor="#android:color/white"
app:tabGravity="fill"
app:tabMode="fixed"
style="#style/MyTabLayout"/>
Related
can you please help me to know how can I change the text below the poster in leanback details view content without losing the position?
this is the code I used:
lb_fullwidth_details_overview_logo
<?xml version="1.0" encoding="utf-8"?><!-- This is an override of the full width details overview logo layout -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/container"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/details_overview_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:elevation="#dimen/lb_details_overview_z"
android:maxHeight="#dimen/lb_details_v2_logo_max_height"
android:maxWidth="#dimen/lb_details_v2_logo_max_width" />
<TextView
android:id="#+id/statusText"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
CustomDetailsOverviewLogoPresenter
class CustomDetailsOverviewLogoPresenter(private val entitlementStatus: String) :
DetailsOverviewLogoPresenter() {
internal class ViewHolder(view: View?) :
DetailsOverviewLogoPresenter.ViewHolder(view) {
override fun getParentPresenter(): FullWidthDetailsOverviewRowPresenter {
return mParentPresenter
}
override fun getParentViewHolder(): FullWidthDetailsOverviewRowPresenter.ViewHolder {
return mParentViewHolder
}
}
override fun onCreateViewHolder(parent: ViewGroup): Presenter.ViewHolder {
val cardView = DetailsOverviewCardView(parent.context)
val width: Int = ViewGroup.LayoutParams.WRAP_CONTENT
val height: Int = ViewGroup.LayoutParams.WRAP_CONTENT
cardView.layoutParams = MarginLayoutParams(width, height)
return ViewHolder(cardView)
}
override fun onBindViewHolder(viewHolder: Presenter.ViewHolder, item: Any) {
val row = item as DetailsOverviewRow
val cardView = viewHolder.view as DetailsOverviewCardView
val imageView = cardView.imageView
val status = cardView.statusText
status.text = entitlementStatus
imageView.setImageDrawable(row.imageDrawable)
if (isBoundToImage(viewHolder as ViewHolder, row)) {
viewHolder.parentPresenter.notifyOnBindLogo(viewHolder.parentViewHolder)
}
}
}
but now the image is not in the position it must be
You need to create a custom DetailsOverviewLogoPresenter. When you construct your FullWidthDetailsOverviewRowPresenter, the first parameter is the Presenter to use to render the description and the second one is the DetailsOverviewLogoPresenter.
In your DetailsOverviewLogoPresenter, implement onCreateView (to inflate and return the view you want to use), onCreateViewHolder (to wrap the returned view in a ViewHolder), and onBindViewHolder (to use the ViewHolder to set up the views including the image and your custom TextView's text).
The official sample has a setupAdapter method that shows how to create and use custom presenters.
I have to populate two tabs in TabbedPage in such a way that two tabs should take equal half widths of the tab.
Here is my code in TabbedPage:
protected override void OnAppearing()
{
base.OnAppearing();
EquipmentGeneralInfoTab = new EquipmentGeneralInfoTab() { Title = "General" };
EquipmentMaintenanceTab = new EquipmentMaintenanceTab() { Title = "Maintenance" };
this.Children.Add(EquipmentGeneralInfoTab);
this.Children.Add(EquipmentMaintenanceTab);
}
Xaml code:
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TCRMobile.Pages.EquipmentInfoTabbedPage"
Title="Equipment">
Tabbar.xaml:
<android.support.design.widget.TabLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="#style/Your.Theme"
app:tabIndicatorColor="#color/tcr_green"
app:tabSelectedTextColor="#color/tcr_green"
app:tabTextColor="#color/black"
app:tabGravity="fill"
app:tabMaxWidth="0dp"
app:tabTextAppearance="#style/tab_text"
app:tabMode="scrollable" />
How to accomplish my requirement?
Try to change the following code in Tabbar.xaml
app:tabMode="scrollable"
To
app:tabMode="fixed"
I trying to add a navigation title icon to my app in one of the page and the code that i have used is:
For iOS:
NavigationPage.SetTitleIcon(this, "icon.png");
For Android in the ToolBar.axml I have added a ImageView as shown below:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<ImageView
android:id="#+id/titleicon"
android:src="#drawable/UstNameIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.v7.widget.Toolbar>
The issue is that, I want my Navigtion icon to get disabled in my next Page and put a title instead of icon.
For that, I tried
For iOS:
NavigationPage.SetTitleIcon(this, null);
NavigationPage.Title="Title";
For Android, How can i achieve the change of Navigation title?
In MainActivity.cs
[Activity (Label = "Todo.Android.Android", MainLauncher = true, Icon="#android:color/transparent")]
For Title, you can set Title property in xaml or c#
To change text you just simple need to find that element by id, and set up a title:
var toolbar =
FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); // it may be simplifed
SetSupportActionBar(toolbar);
toolbar.Title = "title";
And image is under toolbar.Logo, so you can just try:
toolbar.Logo = null;
If you have some data in resources which you want to put in, you can use also:
toolbar.SetTitle();
toolbar.SetLogo();
Noob to Java so I have limited knowledge. I have 2 RelativeLayouts which will hold images of a 13 card hand. One for all the cards and one slightly offset which show which cards can be played. Xml is fairly straight forward
<!--Player viewable cards-->
<RelativeLayout
android:orientation="vertical"
android:layout_width="200dp"
android:layout_height="680dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="100dp"
android:layout_marginLeft="15dp"
android:id="#+id/rlUserViewCards">
<ImageView
android:layout_width="100dp"
android:layout_height="85dp"
android:src="#drawable/c001"
android:rotation="90"
android:tag="1"
android:id="#+id/card1"
android:clickable="false">
</ImageView>
<ImageView
android:layout_width="100dp"
android:layout_height="85dp"
android:src="#drawable/c002"
android:rotation="90"
android:id="#+id/card2"
android:layout_below="#+id/card1"
android:layout_marginTop="-65dp"
android:clickable="false">
</ImageView>
and so on for 13 Images. I can then create a View of the relativelayout looping through the children making images INVISIBLE/VISIBLE, Clickable or not. Does this seem like a good approach?
If so, my problem when first setting the relativelayout is that I can do above as well as set Tag with the card value, I can't figure how to get the integer for the ImageView via findViewById.
userViewCards = (RelativeLayout) findViewById(R.id.rlUserViewCards);
userPickCards = (RelativeLayout) findViewById(R.id.rlUserPlayCards);
View v = userViewCards.getChildAt(0);
Resources res = getResources();
int resId = res.getIdentifier("s204", "drawable", getPackageName());
Drawable drawable = ResourcesCompat.getDrawable(getResources(), res.getIdentifier("s204", "drawable", getPackageName()), null);
ImageView insertImage = (ImageView) findViewById(??);
insertImage.setImageDrawable(drawable);
Can anyone point me in the right direction?
Thanks!
You can set a tag value to the imageView and recieve it in your activity as follows
<ImageView
android:layout_width="100dp"
android:layout_height="85dp"
android:src="#drawable/c001"
android:rotation="90"
android:tag="1"
android:id="#+id/card1"
android:clickable="false">
#OnClick({R.id.card1, R.id.card2, R.id.card3, R.id.card4})
public void selectedCard(View view) {
String selectedCard = view.getTag().toString();
Log.d(TAG, "Mode Selected : " + mode);
switch (Integer.parseInt(mode)) {
case Constant.Card1:
// Do something here
break;
case Constant.Card2:
// Do something here
break;
case Constant.Card3:
// Do something here
break;
case Constant.Card4:
// Do something here
}
}
Note : I am using butterknife here hence the #OnClick()
I can populate the view for my ViewLabel in Nutiteq but I can't set right text in the text views of this Layout .
My code is following
//Setting Popup Label if we click the area
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View labelView = inflater.inflate(R.layout.popup_field, null);
//In order to get a dynamic "redimensionable" Ballon aka ViewLabel
labelView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
labelView.layout(0, 0, labelView.getMeasuredWidth(), labelView.getMeasuredHeight());
//labelView.measure(400, 400);
//labelView.layout(100, 100, 400, 400);
Log.info("drawField:: Nach Label fieldLabel = new ViewLabel... ");
LinearLayout lLayout = (LinearLayout)labelView.findViewById(R.id.layout1);
lLayout.setBackgroundColor(Color.RED);
TextView farmNameTV = (TextView)labelView.findViewById(R.id.farmName);
TextView areaTV = (TextView)labelView.findViewById(R.id.area);
TextView statusTV = (TextView)labelView.findViewById(R.id.status);
farmNameTV.setTextColor(Color.BLACK);
farmNameTV.setText("Farm CacoCaCoca");
areaTV.setTextColor(Color.BLACK);
String areaString = "12.34"
areaTV.setText("Area "+areaString);
statusTV.setTextColor(Color.BLACK);
String statusString = "Status:::qwertzuiopasdfghjklyxcvbnm";
statusTV.setText(statusString);
*What you can see red is my inflated View.
R.layout.popup_field looks like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/farmName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/farmName"/>
<TextView
android:id="#+id/area"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/area"/>
<TextView
android:id="#+id/status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/status"/>
where strings are
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Nutiteq3D</string>
<string name="area">Area</string>
<string name="status">Status</string>
<string name="farmName">Farm Name</string>
</resources>
Have anyone done this task already? Can anyone help me to find out my error(s)?
With MapView of google Api is easy but I develop this with Nutiteq and just pure Activities, so, NO fragments and to inflate we typically need a ViewGroup and this ViewGroup under G-Api would be MapView so inherits from ViewGroup but in Nutiteq is not like this, MapView of Nutiteq inherits of android.view and I can't casting, I can just assign as ViewGroup a null in the call of inflateas you can see.
So, people, I'd be very thankful for your help.
Kind Regards
Solved!
It didn't have to do with ViewLabel but the normal Android.View, I wanted to assign Text to TextView's after I declared my resizable View and therefore it didn't work fine.
So the solution is writing all of tv.setText above
labelView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
labelView.layout(0, 0, labelView.getMeasuredWidth(), labelView.getMeasuredHeight());