代码拉取完成,页面将自动刷新
package com.example.myapplication1;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class MainActivity extends Activity implements View.OnClickListener {
private Fragment findweixn = new findweixin();
private Fragment friendweixin = new friend();
private Fragment configweixin = new configweixin();
private Fragment contentweixin = new contentweixin();
private FragmentManager fragmentManager;
private LinearLayout linearLayout1,linearLayout2,linearLayout3,linearLayout4;
private ImageView imageView1,imageView2,imageView3,imageView4;
private Button button7;
private MyService2.Mybinder mybinder;
private ServiceConnection connection;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
linearLayout1=findViewById(R.id.LinearLayout_wechat);
linearLayout2=findViewById(R.id.LinearLayout_wechat0);
linearLayout3=findViewById(R.id.LinearLayout_wechat1);
linearLayout4=findViewById(R.id.LinearLayout_wechat4);
imageView1=findViewById(R.id.imageView1);
imageView2=findViewById(R.id.imageView2);
imageView3=findViewById(R.id.imageView3);
imageView4=findViewById(R.id.imageView4);
linearLayout1.setOnClickListener(this);
linearLayout2.setOnClickListener(this);
linearLayout3.setOnClickListener(this);
linearLayout4.setOnClickListener(this);
initFragment();
}
private void initFragment(){
fragmentManager=getFragmentManager();
FragmentTransaction transaction=fragmentManager.beginTransaction();
transaction.add(R.id.id_content, configweixin);
transaction.add(R.id.id_content,contentweixin);
transaction.add(R.id.id_content,findweixn);
transaction.add(R.id.id_content,friendweixin);
hideFragment(transaction);
transaction.commit();
}
private void hideFragment( FragmentTransaction transaction){
transaction.hide(friendweixin);
transaction.hide(findweixn);
transaction.hide(contentweixin);
transaction.hide(configweixin);
}
private void showfragment(int i){
FragmentTransaction transaction=fragmentManager.beginTransaction();
hideFragment(transaction);
switch (i){
case 0:
transaction.show(contentweixin);
break;
case 1:
transaction.show(friendweixin);
break;
case 2:
transaction.show(findweixn);
break;
case 3:
transaction.show(configweixin);
break;
default:
break;
}
transaction.commit();
}
public void reImage(int i)
{
imageView1.setImageResource(R.drawable.weiixn4);
imageView2.setImageResource(R.drawable.friend2);
imageView3.setImageResource(R.drawable.find2);
imageView4.setImageResource(R.drawable.config2);
switch (i)
{
case 0:
imageView1.setImageResource((R.drawable.weixin1));
break;
case 1:
imageView2.setImageResource(R.drawable.friend1);
break;
case 2:
imageView3.setImageResource(R.drawable.find1);
break;
case 3:
imageView4.setImageResource(R.drawable.config1);
break;
default:
break;
}
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.LinearLayout_wechat0:
reImage(0);
showfragment(0);
break;
case R.id.LinearLayout_wechat1:
reImage(1);
showfragment(1);
break;
case R.id.LinearLayout_wechat:
reImage(2);
showfragment(2);
break;
case R.id.LinearLayout_wechat4:
reImage(3);
showfragment(3);
break;
default:
break;
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。