我正在尝试为不同的页面创建不同的操作栏。例如,一些页面将有一个标题和一个帮助按钮,其他页面应该有一个设置按钮。
如何使用Xamarin.Android中的自定义导航渲染器实现这一目标?
自定义导航渲染器的示例代码:
[assembly: ExportRenderer(typeof(CustomNavigationPage), typeof(CustomNavigationPageRenderer))]
namespace MobileAppSamples.Droid.CustomRenderers
{
public class CustomNavigationPageRenderer : NavigationRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<NavigationPage> e)
{
base.OnElementChanged(e);
if (Element != null)
{
var actionBar = ((Activity)Context).ActionBar;
Android.Widget.LinearLayout layout = new Android.Widget.LinearLayout(Context);
layout.Orientation = Orientation.Horizontal;
layout.WeightSum = 100;
TextView title = new TextView(Context);
title.Text = "sample";
ViewGroup.LayoutParams textlp = new ViewGroup.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent);
layout.AddView(title, textlp);
actionBar.SetCustomView(layout, new ActionBar.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent));
actionBar.SetDisplayOptions(ActionBarDisplayOptions.ShowCustom, ActionBarDisplayOptions.ShowCustom | ActionBarDisplayOptions.ShowHome );
}
}
}
}
答案 0 :(得分:0)
问题是你得到的活动。 测试此代码:
$(function()
{
$("#QtChar")[0].innerText = "Quantidade de Caracteres Restantes "+ parseInt($("#txtMensagem")[0].maxLength);
});
function tamanhoMensagem()
{
$("#QtChar")[0].innerText = "Quantidade de Caracteres Restantes "+ parseInt($("#txtMensagem")[0].maxLength - $("#txtMensagem").val().length);
}