您好,我设法从本教程https://www.youtube.com/watch?v=HrLLnoa9Zd4&index=32&list=WL&t=330s中复制了代码。
但是后来我决定在左幻灯片中添加一些简单的操作,例如按钮,以更改其文本。我使用SetContentView(Resource.Layout.Left);
创建了一个新活动,并将click事件写入了按钮。但是,当我启动程序时,我单击了按钮,但没有任何反应。我发现实际上没有调用该活动,而我看到的只是布局。
我的问题是,当我向左滑动时,是否可以调用我编写的活动?
主要布局
<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">
<com.jkb.slidemenu.SlideMenuLayout
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/slideMenuLayout1"
app:contentToggle="true"
app:contentAlpha="0.5"
app:parallax="false"
app:slideMode="both">
<include layout="@layout/Left" />
<include layout="@layout/Right" />
<include layout="@layout/MainView" />
</com.jkb.slidemenu.SlideMenuLayout>
</RelativeLayout>
左侧布局
<Button
android:text="Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/leftBtn" />
<TextView
android:text="Slide Left"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minWidth="25px"
android:minHeight="25px"
android:id="@+id/leftText" />
左活动
Button btn = FindViewById<Button>(Resource.Id.leftBtn);
TextView text = FindViewById<TextView>(Resource.Id.leftText);
btn.Click += (sender, e) => { text.Text = "text is chaged"; };
答案 0 :(得分:0)
我做了一个有关使用SlideMenuLayout的演示,但是我无法重现您的问题,并且可以更改content_menu_left视图的按钮文本,这是我的示例:
main.axml:
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.jkb.slidemenu.SlideMenuLayout
android:id="@+id/mainSlidemenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
app:contentAlpha="0.5"
app:contentToggle="true"
app:parallax="false"
app:slideMode="both">
<include layout="@layout/content_menu_left"/>
<include layout="@layout/content_menu_right"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="this is slide menu main layout"
android:textSize="22sp" />
</com.jkb.slidemenu.SlideMenuLayout>
</LinearLayout>
左菜单:
<?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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="left menu"
android:textSize="22sp" />
<Button
android:id="@+id/btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="left menu" />
</LinearLayout>
Button button1;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
//SetContentView(Resource.Layout.activity_main);
SetContentView(Resource.Layout.activity_main);
button1 = (Button)FindViewById(Resource.Id.btn1);
button1.Click += Button1_Click;
}
private void Button1_Click(object sender, System.EventArgs e)
{
button1.Text = "this is test";
}
答案 1 :(得分:0)
我知道了。我可以使用fragments
代替include
。
main.axml将如下所示
<com.jkb.slidemenu.SlideMenuLayout
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/slideMenuLayout1"
app:contentToggle="true"
app:contentAlpha="0.5"
app:parallax="false"
app:slideMode="both">
<fragment
class="NameSpace.FragmentName" //it is important to write the namespace and gragment name
android:layout = "@layout/Left" //here you choose the layout you want to render
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/RightFragment" />
//repeat the same for the Right and Main view
</com.jkb.slidemenu.SlideMenuLayout>
还有fragment.cs,您只需要这个
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreateView(inflater, container, savedInstanceState);
View view = inflater.Inflate(Resource.Layout.YourLayout, container, false);
}