Example usage for android.widget TextView TextView

List of usage examples for android.widget TextView TextView

Introduction

In this page you can find the example usage for android.widget TextView TextView.

Prototype

public TextView(Context context) 

Source Link

Usage

From source file:com.aengbee.android.leanback.presenter.GridItemPresenter.java

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    TextView view = new TextView(parent.getContext());

    Resources res = parent.getResources();
    int width = res.getDimensionPixelSize(R.dimen.grid_item_width);
    int height = res.getDimensionPixelSize(R.dimen.grid_item_height);

    view.setLayoutParams(new ViewGroup.LayoutParams(width, height));
    view.setFocusable(true);/*  ww w .j  ava 2  s . c o m*/
    view.setFocusableInTouchMode(true);
    view.setBackgroundColor(ContextCompat.getColor(parent.getContext(), R.color.default_background));
    view.setTextColor(Color.WHITE);
    view.setGravity(Gravity.CENTER);
    return new ViewHolder(view);
}

From source file:com.banditcat.example.view.bottombar.SampleFragment.java

@Nullable
@Override/*from  w w w  . j  a  va 2  s  . c o  m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    TextView textView = new TextView(getActivity());
    textView.setText(getArguments().getString(ARG_TEXT));

    return textView;
}

From source file:com.adstrosoftware.gpsplayground.InvalidFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    TextView textView = new TextView(getActivity());

    textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    textView.setText(R.string.illegalFeature);
    textView.setGravity(Gravity.CENTER);

    return textView;
}

From source file:com.actionbarsherlock.sample.knownbugs.Issue379.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ActionBar ab = getSupportActionBar();
    ab.setNavigationMode(NAVIGATION_MODE_TABS);
    ab.addTab(ab.newTab().setTabListener(this).setText("Test"));

    TextView tv = new TextView(this);
    tv.setText("ColorDrawable ignores bounds on pre-HC. Make sure you see three colors.");
    setContentView(tv);//from   w ww .ja  va  2 s.  co  m
}

From source file:com.adstrosoftware.animationplayground.InvalidFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    TextView textView = new TextView(getActivity());

    textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    textView.setText(R.string.illegalAnimation);
    textView.setGravity(Gravity.CENTER);

    return textView;
}

From source file:com.connectsdk.smarthomesampler.dialog.AcknowledgementsFragmentDialog.java

@NonNull
@Override/*from w w w  .j  a  va  2s . c om*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Context context = getActivity();
    final TextView message = new TextView(context);
    message.setText(Html.fromHtml(context.getString(R.string.info_message)));
    message.setMovementMethod(LinkMovementMethod.getInstance());
    int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 25,
            context.getResources().getDisplayMetrics());
    message.setPadding(padding, 0, padding, 0);
    ScrollView scrollView = new ScrollView(context);
    scrollView.addView(message);

    return new AlertDialog.Builder(context).setTitle(R.string.info_title).setView(scrollView)
            .setCancelable(true).create();
}

From source file:at.wada811.android.library.demos.SplashActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // catch UncaughtException
    Thread.setDefaultUncaughtExceptionHandler(new CrashExceptionHandler(getApplicationContext()));
    super.onCreate(savedInstanceState);
    // ???????/*from ww  w  .java 2 s  . com*/
    File file = ResourceUtils.getFile(this, CrashExceptionHandler.FILE_NAME);
    if (file.exists()) {
        String report = ResourceUtils.readFileString(this, CrashExceptionHandler.FILE_NAME);
        ScrollView scrollView = new ScrollView(this);
        TextView textView = new TextView(this);
        textView.setText(report);
        scrollView.addView(textView);
        setContentView(scrollView);
        file.delete();
    } else {
        startActivity(new Intent(this, MainActivity.class));
        finish();
    }
}

From source file:ch.jeda.platform.android.LogFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    this.textView = new TextView(this.getActivity());
    this.textView.setLayoutParams(
            new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
    this.scrollView = new ScrollView(this.getActivity());
    this.scrollView.addView(this.textView);
    this.updateView();
    return this.scrollView;
}

From source file:com.art2cat.dev.moonlightnote.controller.settings.CommonSettingsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    if (getArguments() != null) {
        mType = getArguments().getInt("type");
    }// w  ww . j a v  a  2s .c  om
    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    linearLayout.setLayoutParams(params);
    ScrollView scrollView = new ScrollView(getActivity());
    scrollView.setLayoutParams(params);
    linearLayout.addView(scrollView);
    TextView textView = new TextView(getActivity());
    textView.setLayoutParams(params);
    int padding = getResources().getDimensionPixelOffset(R.dimen.padding);
    textView.setPadding(padding, padding, padding, padding);
    switch (mType) {
    case Constants.FRAGMENT_ABOUT:
        textView.setGravity(Gravity.CENTER);
        textView.setText(getContent());
        getActivity().setTitle(R.string.settings_about);
        break;
    case Constants.FRAGMENT_LICENSE:
        textView.setGravity(Gravity.CENTER);
        textView.setText(getContent());
        getActivity().setTitle(R.string.settings_license);
        break;
    case Constants.FRAGMENT_POLICY:
        textView.setGravity(Gravity.START);
        textView.setText(getContent());
        getActivity().setTitle(R.string.settings_policy);
        break;
    }
    setHasOptionsMenu(true);
    scrollView.addView(textView);
    return linearLayout;
}

From source file:com.actionbarsherlock.sample.demos.app.ActionBarActionItemCustomView.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem item = menu.add(0, android.R.id.copy, 0, "Test");

    final int twentyDp = (int) (20 * getResources().getDisplayMetrics().density);

    TypedArray a = getTheme().obtainStyledAttributes(R.styleable.SherlockTheme);
    final int abHeight = a.getLayoutDimension(R.styleable.SherlockTheme_abHeight, LayoutParams.FILL_PARENT);
    a.recycle();/*from   w  w w.  ja v  a 2s. co  m*/

    LinearLayout l = new LinearLayout(this);
    l.setPadding(twentyDp, 0, twentyDp, 20);
    l.setBackgroundColor(0x55FF0000);

    TextView tv = new TextView(this);
    tv.setText("HI!!");
    tv.setGravity(Gravity.CENTER);
    tv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, abHeight));
    l.addView(tv);

    l.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(ActionBarActionItemCustomView.this, "Got custom action item click!",
                    Toast.LENGTH_SHORT).show();
        }
    });

    item.setActionView(l);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    return super.onCreateOptionsMenu(menu);
}