- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我创建了一个测验应用程序,在第二个java类(Menu2)上有一个按钮,如果有人单击此按钮,则会出现一个弹出窗口,并且背景(Menu2的布局)的alpha/透明度为0.1 。当有人点击IN THE POPUPWINDOW时,弹出窗口会自行关闭,透明度将设置为1。但是,如果有人在弹出窗口之外单击,弹出窗口将关闭,但透明度会持续...我该如何解决这个问题?
菜单2:
public class Menu2 extends AppCompatActivity {
private DrawerLayout mDrawerLayout2;
private ActionBarDrawerToggle mToggle;
private Toolbar mToolbar;
private Button popup;
private PopupWindow popupWindow;private LayoutInflater layoutInflater; //Alows to add a new layout in our window
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu2);
TextView txtScore = (TextView) findViewById(R.id.textScore2);
TextView txtHighScore = (TextView)findViewById(R.id.textHighScore);
ImageView imgTrophyView1 = (ImageView)findViewById(R.id.trophy1);
ImageView imgTrophyView2 = (ImageView) findViewById(R.id.trophy2);
TextView trophy1Txt = (TextView) findViewById(R.id.trophy1Text);
TextView trophy2Txt = (TextView) findViewById(R.id.trophy2Text);
Intent intent = getIntent();
int mScore = intent.getIntExtra ("score",0);
txtScore.setText("Your score is: " + mScore);
SharedPreferences sharedpreferences = getSharedPreferences("mypref", Context.MODE_PRIVATE);
int applyView =sharedpreferences.getInt("currentscore",0);
SharedPreferences mypref =getPreferences(MODE_PRIVATE);
int highScore = mypref.getInt("highScore", 0);
if (highScore>= mScore)
txtHighScore.setText("High score: " + highScore);
else{
txtHighScore.setText("New highscore: " + mScore);
SharedPreferences.Editor editor = mypref.edit();
editor.putInt("highScore",mScore);
editor.commit();
}
if (applyView >=10) {
imgTrophyView1.setVisibility(View.VISIBLE);
trophy1Txt.setVisibility(View.VISIBLE);
}
if (applyView >= 20){
imgTrophyView2.setVisibility(View.VISIBLE);
trophy2Txt.setVisibility(View.VISIBLE);
}
popup = (Button)findViewById(R.id.enablePOPUP);
popup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
layoutInflater =(LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
ViewGroup container = (ViewGroup)layoutInflater.inflate(R.layout.popup_menu2_1,null);
popupWindow = new PopupWindow(container,1000,980,true); //400,400=popUp size, true = makes that we can close the pop up by simply click out of the window
popupWindow.showAtLocation(mDrawerLayout2, Gravity.CENTER, 0, 0);
mDrawerLayout2.setAlpha((float) 0.1);
container.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View view, MotionEvent motionEvent ){
mDrawerLayout2.setAlpha((float) 1);
popupWindow.dismiss();
return true;
}
});
}
});
mToolbar = (Toolbar)findViewById(R.id.nav_action);
setSupportActionBar(mToolbar);
mDrawerLayout2 = (DrawerLayout) findViewById(R.id.drawerLayout2);
mToggle = new ActionBarDrawerToggle(this, mDrawerLayout2, R.string.open, R.string.close);
mDrawerLayout2.addDrawerListener(mToggle);
mToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
NavigationView mNavigationView = (NavigationView) findViewById(nv2);
mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem){
switch (menuItem.getItemId()){
case(R.id.nav_home2):
Intent accountActivity2 = new Intent(getApplicationContext(),QuizActivity.class);
startActivity(accountActivity2);
}
return true;
}
});}
public void onClick(View view) {
Intent intent = new Intent(Menu2.this, QuizActivity.class);
startActivity(intent);
}
@Override //Makes that the "Burger" Item, shows the Drawer if someone clicks on the simbol
public boolean onOptionsItemSelected(MenuItem item) {
if (mToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
菜单2 XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
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"
tools:context="amapps.impossiblequiz.Menu2"
android:id="@+id/drawerLayout2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
layout="@layout/navigation_action"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<TextView
android:id="@+id/trophy2Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="20 points= High knowledge"
android:visibility="invisible"
android:layout_alignTop="@+id/trophy1Text"
android:layout_alignLeft="@+id/trophy2"
android:layout_alignStart="@+id/trophy2"
android:layout_alignRight="@+id/trophy2"
android:layout_alignEnd="@+id/trophy2" />
<TextView
android:id="@+id/textScore2"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:background="#f60"
android:paddingTop="10dp"
android:paddingLeft="35dp"
android:text="Your score is:"
android:textAppearance="@style/TextAppearance.AppCompat"
android:textColor="#ffffff"
android:textSize="20dp"
android:layout_marginTop="28dp"
android:layout_below="@+id/textView2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:id="@+id/textHighScore"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:background="#FFAB00"
android:paddingLeft="35dp"
android:paddingRight="100dp"
android:paddingTop="10dp"
android:text="Highest score:"
android:textAppearance="@style/TextAppearance.AppCompat"
android:textColor="#ffffff"
android:textSize="20dp"
android:layout_marginTop="13dp"
android:layout_below="@+id/textScore2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:id="@+id/tryAgain_button"
android:layout_width="150dp"
android:layout_height="50dp"
android:background="@drawable/bg_pill"
android:onClick="onClick"
android:text="Restart Quiz!"
android:textColor="#ffffff"
android:layout_marginTop="18dp"
android:layout_below="@+id/textHighScore"
android:layout_centerHorizontal="true" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="33dp"
android:text="Stats: play and get trophies!"
android:textAppearance="@style/TextAppearance.AppCompat.Button"
android:textSize="20dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<ImageView
android:id="@+id/trophy1"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/tryAgain_button"
android:layout_marginLeft="26dp"
android:layout_marginStart="26dp"
android:layout_marginTop="40dp"
android:visibility="invisible"
app:srcCompat="@drawable/trophy1" />
<ImageView
android:id="@+id/trophy2"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignTop="@+id/trophy1"
android:layout_marginLeft="24dp"
android:layout_marginStart="24dp"
android:layout_toEndOf="@+id/trophy1"
android:layout_toRightOf="@+id/trophy1"
android:visibility="invisible"
app:srcCompat="@drawable/trophy2" />
<TextView
android:id="@+id/trophy1Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10 points= Basic intelligence"
android:visibility="invisible"
android:layout_below="@+id/trophy1"
android:layout_alignLeft="@+id/trophy1"
android:layout_alignStart="@+id/trophy1"
android:layout_marginTop="23dp"
android:layout_toLeftOf="@+id/trophy2"
android:layout_toStartOf="@+id/trophy2" />
<ImageView
android:id="@+id/statsTrophy"
app:srcCompat="@drawable/statsoftrophy"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignTop="@+id/textHighScore"
android:layout_above="@+id/tryAgain_button"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:id="@+id/enablePOPUP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_below="@+id/trophy2"
android:layout_alignRight="@+id/textView2"
android:layout_alignEnd="@+id/textView2" />
</RelativeLayout>
</LinearLayout>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="@menu/navigation_menu2"
android:layout_gravity="start"
android:id="@+id/nv2"
app:headerLayout="@layout/navigation_header"
app:itemIconTint="@drawable/tint_color_selector2">
</android.support.design.widget.NavigationView>
最佳答案
尝试这样做:
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
mDrawerLayout2.setAlpha((float) 1);
popup.dismiss();
}
});
关于java - 如何使用触摸监听器停用布局的 alpha "color",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45238134/
我想在按下按钮时在屏幕上显示透明的布局。 我尝试过使用Stack,它工作正常,但是当我按下函数内部的按钮(例如ExercisePage())时,覆盖图不显示。 当值overlayShouldBeVis
假设我有一个 html table其中单元格包含 span秒。某些操作会导致 div span s改变他们的位置,比如我重构表格转置。 考虑 1 2 3
我正在尝试在 RelativeLayout 上使用 Scale Animation。我想从左角到右角缩放图像,即从下到上对角线(从左到右)。我使用了以下代码行,但没有得到预期的结果。谁能用简单的话向我
我有两个 RelativeLayouts,每个包含一个 TextView。 基本上,顶部布局 用作“按钮”。当点击时,另一个布局将播放它的动画(向下扩展)。 在这种情况下,我应该向哪个layout 添
我只是想知道 JavaFx 中是否有任何简单的动 Canvas 局方法,例如 VBox 和 HBox。我希望我的应用程序在指定时间后更改 VBox 的背景颜色。但我意识到没有任何类似于 FillTra
简而言之,我想缩放 View - 就像 Android Market 一样,当您单击“更多”按钮时,例如在“描述”上。 我发现,Android Market 具有以下结构的布局: > 64d
要求 我可以根据 toYDelta="100% 或 toYDelta="50% 等转换布局 但我只想在 300dp 高度 中设置动 Canvas 局。 slide_down.xml slide_up
我是一名优秀的程序员,十分优秀!