为什么这个 import static <project-name> .R.id.snackbarView
Why this import static <project-name> .R.id.snackbarView
我们为正在使用 Snackbar 的 Activity 添加了 android.support.design.widget.CoordinatorLayout
到 XML 文件。所有 Gradle 信息都是正确的,另外两个相应的导入是导入的 minSdk 是 19 支持设计是 v25.3.1 我的问题是为什么会发生这种导入,我是否在某处省略了一些设置?
原始 XML 代码文件有一个相对布局加上其他项目和 CoordinatorLayout 小部件的 XML
小吃店代码
public void showSnackbar(){
//coordinatorLayout = findViewById(snackbarView);
//Snackbar snackbar = null;
final Snackbar snackbar = Snackbar
.make(findViewById(snackbarView), getText(R.string.snackbar_text),1);
snackbar.setActionTextColor(Color.RED);
snackbar.setAction("EXIT", new View.OnClickListener(){
@Override
public void onClick(View view) {
//Intent intent = new Intent(DetailsActivity.this, MainActivity.class);
//startActivity(intent);
snackbar.dismiss();
}
});
TextView snackbarActionTextView = (TextView) snackbar.getView().findViewById( android.support.design.R.id.snackbar_action );
snackbarActionTextView.setTextSize( 30 );
snackbarActionTextView.setTypeface(snackbarActionTextView.getTypeface(), Typeface.BOLD);
TextView snackbarTextView = (TextView) snackbar.getView().findViewById(android.support.design.R.id.snackbar_text);
snackbarTextView.setTextSize( 30 );
snackbarTextView.setMaxLines( 3 );
snackbarTextView.setTextColor(Color.YELLOW);
snackbar.setDuration(Snackbar.LENGTH_INDEFINITE);
snackbar.show();
}
这是我的导入
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
James_Duh 这里有一些代码可以创建一个没有 Action 按钮的普通 Snackbar,另一种方法可以创建一个带有 Action 按钮的 Snackbar enjoy 不确定导入吗?
public void onPLAIN(View view){
noActLayout = (CoordinatorLayout)findViewById(R.id.USE_ME_TWICE);
sbNoAct = Snackbar.make(noActLayout,R.string.real_csb_noaction_text,1);// any interger will make it happy
sbNoAct.setDuration(4000);// 4 sec // OR Snackbar.LENGTH_LONG matters NOT you are setting duration here
View sbView = sbNoAct.getView();
sbView.setBackgroundColor(ContextCompat.getColor(this, R.color.color_lightBlue));
TextView textViewNoAct = sbView.findViewById(android.support.design.R.id.snackbar_text);
//set text color
textViewNoAct.setTextColor(ContextCompat.getColor(this,R.color.color_White));
textViewNoAct.setMaxLines(10);
textViewNoAct.setTextSize(18);
//increase max lines of text in snackbar. default is 2.
sbNoAct.show();
}
public void onWithAct(View view){
myLayout = (CoordinatorLayout) findViewById(R.id.USE_ME_TWICE);
sb = Snackbar.make(myLayout, R.string.real_csb_text, Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.real_csb_action, myOnClickListener)
.setActionTextColor(ContextCompat.getColor(context, R.color.color_Red));
View sbView = sb.getView();
sbView.setBackgroundColor(ContextCompat.getColor(this, R.color.color_White));
TextView textView = sbView.findViewById(android.support.design.R.id.snackbar_text);
//set text color
textView.setTextColor(ContextCompat.getColor(this,R.color.color_deepBlue));
textView.setTextSize(18);
//increase max lines of text in snackbar. default is 2.
textView.setMaxLines(10);
// NOTE new View
TextView textAction = sbView.findViewById(android.support.design.R.id.snackbar_action);
//set Action text color
textAction.setTextColor(ContextCompat.getColor(this,R.color.color_Red));
textAction.setTextSize(18);
sb.show();
}
View.OnClickListener myOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
//sb.dismiss();
System.out.println("=== I WAS DISMISSED OR SENT TO MainActivity===");
// OR use and Intent to go somewhere have a nice trip
Intent intent = new Intent(PageThreeActivity.this, MainActivity.class);
startActivity(intent);
}
};
}
我们为正在使用 Snackbar 的 Activity 添加了 android.support.design.widget.CoordinatorLayout
到 XML 文件。所有 Gradle 信息都是正确的,另外两个相应的导入是导入的 minSdk 是 19 支持设计是 v25.3.1 我的问题是为什么会发生这种导入,我是否在某处省略了一些设置?
原始 XML 代码文件有一个相对布局加上其他项目和 CoordinatorLayout 小部件的 XML
小吃店代码
public void showSnackbar(){
//coordinatorLayout = findViewById(snackbarView);
//Snackbar snackbar = null;
final Snackbar snackbar = Snackbar
.make(findViewById(snackbarView), getText(R.string.snackbar_text),1);
snackbar.setActionTextColor(Color.RED);
snackbar.setAction("EXIT", new View.OnClickListener(){
@Override
public void onClick(View view) {
//Intent intent = new Intent(DetailsActivity.this, MainActivity.class);
//startActivity(intent);
snackbar.dismiss();
}
});
TextView snackbarActionTextView = (TextView) snackbar.getView().findViewById( android.support.design.R.id.snackbar_action );
snackbarActionTextView.setTextSize( 30 );
snackbarActionTextView.setTypeface(snackbarActionTextView.getTypeface(), Typeface.BOLD);
TextView snackbarTextView = (TextView) snackbar.getView().findViewById(android.support.design.R.id.snackbar_text);
snackbarTextView.setTextSize( 30 );
snackbarTextView.setMaxLines( 3 );
snackbarTextView.setTextColor(Color.YELLOW);
snackbar.setDuration(Snackbar.LENGTH_INDEFINITE);
snackbar.show();
}
这是我的导入
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
James_Duh 这里有一些代码可以创建一个没有 Action 按钮的普通 Snackbar,另一种方法可以创建一个带有 Action 按钮的 Snackbar enjoy 不确定导入吗?
public void onPLAIN(View view){
noActLayout = (CoordinatorLayout)findViewById(R.id.USE_ME_TWICE);
sbNoAct = Snackbar.make(noActLayout,R.string.real_csb_noaction_text,1);// any interger will make it happy
sbNoAct.setDuration(4000);// 4 sec // OR Snackbar.LENGTH_LONG matters NOT you are setting duration here
View sbView = sbNoAct.getView();
sbView.setBackgroundColor(ContextCompat.getColor(this, R.color.color_lightBlue));
TextView textViewNoAct = sbView.findViewById(android.support.design.R.id.snackbar_text);
//set text color
textViewNoAct.setTextColor(ContextCompat.getColor(this,R.color.color_White));
textViewNoAct.setMaxLines(10);
textViewNoAct.setTextSize(18);
//increase max lines of text in snackbar. default is 2.
sbNoAct.show();
}
public void onWithAct(View view){
myLayout = (CoordinatorLayout) findViewById(R.id.USE_ME_TWICE);
sb = Snackbar.make(myLayout, R.string.real_csb_text, Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.real_csb_action, myOnClickListener)
.setActionTextColor(ContextCompat.getColor(context, R.color.color_Red));
View sbView = sb.getView();
sbView.setBackgroundColor(ContextCompat.getColor(this, R.color.color_White));
TextView textView = sbView.findViewById(android.support.design.R.id.snackbar_text);
//set text color
textView.setTextColor(ContextCompat.getColor(this,R.color.color_deepBlue));
textView.setTextSize(18);
//increase max lines of text in snackbar. default is 2.
textView.setMaxLines(10);
// NOTE new View
TextView textAction = sbView.findViewById(android.support.design.R.id.snackbar_action);
//set Action text color
textAction.setTextColor(ContextCompat.getColor(this,R.color.color_Red));
textAction.setTextSize(18);
sb.show();
}
View.OnClickListener myOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
//sb.dismiss();
System.out.println("=== I WAS DISMISSED OR SENT TO MainActivity===");
// OR use and Intent to go somewhere have a nice trip
Intent intent = new Intent(PageThreeActivity.this, MainActivity.class);
startActivity(intent);
}
};
}